You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
This issue is reporting what seems to me an inconsistency with TypeScript behaviour.
Since this pull request, TypeScript allows a type to represent all the strings that are Uppercase, Lowercase, Capitalize, or Uncapitalize.
These types are Uppercase<string>, Lowercase<string>Capitalize<string> and Uncapitalize<string> respectively.
However it seems that typebox doesn't support this feature.
Applying an intrinsic type on a string type gives a TString type, which is then inferred into string type instead of following the TypeScript behaviour.
For example:
constLowercaseStringSchema=Type.Lowercase(Type.String())// LowercaseStringSchema is TStringtypeLowercaseStringType=Static<typeofLowercaseStringSchema>// LowercaseStringType is string
But in TypeScript:
typeLowercaseString=Lowercase<string>// LowercaseString is Lowercase<string> instead of string
Would it be possible to support this feature when inferring the static type of a schema?
Maybe there is a good reason not to support this feature and I missed it, apologies if this is the case.
Thank you for supporting this package!
The text was updated successfully, but these errors were encountered:
Thanks for the suggestion, I think this is a good idea. Currently intrinsic string manipulation types are only supported for remapping finite literal/template literal values, with the intrinsic applying an immediate remap of the type.
Where above the return value is evaluated immediately to be { const: 'HELLO' } (which is meaningful to Json Schema). However I can imagine scenarios like the following.
constT=Type.Object({value: Type.Uppercase(Type.String())// only allow strings that are uppercase})
In which case the schema would be { type: 'string', pattern: '^[A-Z]*$' }, and where TypeBox would need to represent that to the type system as TUppercase<T> such that it can be correctly composed with other types, such as TemplateLiteral.
I will do a review of what would be required to make it work once 0.32.0 is published. Unfortunately, I don't expect this functionality to land soon (as I expect implementing this correctly would involve updating a quite a few existing types to ensure they map correctly), but will try pick it up early to mid next year.
Hi @sinclairzx81,
Thanks for considering this suggestion. Using regex in the JSON schema would be very useful as well.
I'm looking forward to seeing it implemented!
Hello,
This issue is reporting what seems to me an inconsistency with TypeScript behaviour.
Since this pull request, TypeScript allows a type to represent all the strings that are
Uppercase
,Lowercase
,Capitalize
, orUncapitalize
.These types are
Uppercase<string>
,Lowercase<string>
Capitalize<string>
andUncapitalize<string>
respectively.However it seems that typebox doesn't support this feature.
Applying an intrinsic type on a string type gives a
TString
type, which is then inferred intostring
type instead of following the TypeScript behaviour.For example:
But in TypeScript:
Would it be possible to support this feature when inferring the static type of a schema?
Maybe there is a good reason not to support this feature and I missed it, apologies if this is the case.
Thank you for supporting this package!
The text was updated successfully, but these errors were encountered: