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
consterrors=Value.Errors(MyType,{type: 'boolish',bool_value: 42});// `bool_value` is incorrectconsole.log(errors);
I get a bunch of errors as TypeBox is trying to match the object against (all?) the union possibilities. This is not too helpful, especially if the union grows larger (we have around 40 variants in one use case). I even spotted that the actual reason might be missing from the error list completely, probably there's some limit when the union is too big?
TypeScript error reporting is working very nicely in this case:
typeMyType=Static<typeofMyType>;constobj: MyType={type: 'boolish',bool_value: 1234,// ERROR: Type "number" is not assignable to type "boolean".}
As a union grows bigger (both in variants and in extra properties), the performance isn't optimal.
There doesn't seem to be an option to specify the "discriminator property" or some automatic discovery as, e.g. in ArkType's unions. I have stumbled upon some earlier discussions about this in typebox, but that was pre-v1 AFAICT.
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
Hi!
In our codebase we make heavy use of discriminated unions. We came across some inconveniences when modelling them via TypeBox:
Error reporting
Let's define the following union:
Now, if I run this:
I get a bunch of errors as TypeBox is trying to match the object against (all?) the union possibilities. This is not too helpful, especially if the union grows larger (we have around 40 variants in one use case). I even spotted that the actual reason might be missing from the error list completely, probably there's some limit when the union is too big?
TypeScript error reporting is working very nicely in this case:
Validation performance
The compiled validator for the above schema is:
As a union grows bigger (both in variants and in extra properties), the performance isn't optimal.
There doesn't seem to be an option to specify the "discriminator property" or some automatic discovery as, e.g. in ArkType's unions. I have stumbled upon some earlier discussions about this in typebox, but that was pre-v1 AFAICT.
Are there any plans to optimize this use case?
Is this comment still valid? #1017 (comment)
Beta Was this translation helpful? Give feedback.
All reactions