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
The error message "locks into" the third union variant and returns error messages based on the assumption the third branch is the correct branch, even though no information is given that could lead to this assumption.
I would expect a union error on the root level instead.
import{type}from"arktype";constThing=type.or({type: "'a'",val1: "number",},{type: "'b'",val2: "number",},{type: "'c' | 'd'",val3: "number",},);// type must be "c" or "d" (was missing)// val3 must be a number (was missing)constout=Thing({});
changed the title [-]Errors for unions without clear discriminator are too narrow[/-][+]Improve partially discriminated error context[/+]on Apr 23, 2025
This is something that's been on my radar for a while and I've recently been considering some ways to address it and get the best of both worlds from the discrimination logic.
FYI, I tried it with jitless: true and for JIT disabled, the error message is expected:
import{configure}from"arktype/config";configure({jitless: true,});const{ type }=awaitimport("arktype");constThing=type.or({type: "'a'",val1: "number",},{type: "'b'",val2: "number",},{type: "'c' | 'd'",val3: "number",},);// type must be "c" or "d", "a" or "b" (was missing)constout=Thing({});
@paulzhng Yeah, the key is combining the extra context you get here which is helpful with the concision you get from discrimination when you really do want to narrow down the error message to apply to a specific branch, possibly with some explanation of why that branch was chosen.
The jitless non-discriminated traversal has to give one error per branch no matter what.
Activity
[-]Errors for unions without clear discriminator are too narrow[/-][+]Improve partially discriminated error context[/+]ssalbdivad commentedon Apr 23, 2025
This is something that's been on my radar for a while and I've recently been considering some ways to address it and get the best of both worlds from the discrimination logic.
paulzhng commentedon Apr 23, 2025
FYI, I tried it with
jitless: trueand for JIT disabled, the error message is expected:ssalbdivad commentedon Apr 23, 2025
@paulzhng Yeah, the key is combining the extra context you get here which is helpful with the concision you get from discrimination when you really do want to narrow down the error message to apply to a specific branch, possibly with some explanation of why that branch was chosen.
The jitless non-discriminated traversal has to give one error per branch no matter what.
feat(sets): discriminate by each value of a literal union
fix(schema): say a missing discriminant key "was missing"
feat(schema): report each branch when a union's discriminant identifi…
ssalbdivad commentedon Nov 18, 2026
Fixed in 3.0.0-beta.0 (#1728). Try it with
npm i arktype@next.