Flosi21
Aarktype
•Created by Flosi21 on 4/16/2025 in #questions
Discriminated union with union type discriminator gives wrong error messages
Let's say I have this type, right here:
This will produce the error message
a must be a string (was missing), b must be a string (was missing) or c must be a string (was missing)
, however what one would expect is a must be a string (was missing)
Now interestingly this only occurs because when more then ONE of the discriminators is a union. This type here will produce the correct error message a must be a string (was missing)
The why becomes apparent when we take a look at the precompilation, in case 2 it can just switch case over the options
where in case 1 it uses the intersectionAllows
which cannot tell, that when option = "A"
the only remaining field to validate will be a
because it checks the WHOLE data instead of just looking at the option and then "locking" in.
Is this a bug? Is there some part of set theory that can justify this behaviour that i do not yet understand? 😅54 replies
Aarktype
•Created by Flosi21 on 4/15/2025 in #questions
type inference resolves types from scopes to never in union
When using types from scopes in a union, arktype will resolve some of them to be "never", however if you insert their definition directly it resolves the type correctly
Here is an example. If you paste this in the playground and hover of the out, the type will resolve to "never" in some places.
Interestingly the .expression tab in the playground resolves the native Typescript expression correctly
Is this a bug or am I misusing scopes in some way?
17 replies
Aarktype
•Created by Flosi21 on 4/9/2025 in #questions
Is it normal for error messages / potentially behaviour to change depending on jitless?
I wanted to do some stuff with discriminated unions with
jitless: true
(due to a bug with jitless that has been fixed) and i noticed that the validation behaviour was different when i set it to jitless: false
. Sadlly i didn't manage to reproduce the different validation behaviour but if you paste this into the web playground
you will see that the error message differs depending on the jitless
setting. Is this intended?2 replies