Adding a field to a union variant which refers to the union affects errors reported for other variants.
π Search Terms
union, path, key
π§© Context
- ArkType version: 2.2.1 (latest)
- TypeScript version (5.1+): 7
π§βπ» Repro
Playground Link
import { scope, type } from "arktype"
const api = scope({
Field: {
type: "'field'",
value: "string >= 1"
},
Group: {
type: "'group'",
// comment this out, errors will change
parts: "Part[]"
},
Part: "Field | Group"
}).export()
const Thing = type({
parts: api.Part.array()
})
const out = Thing({
parts: [{ type: "field", value: "" }]
})
In this example, I am not validating any Groups. I'm validating a single Field whose value is too short. I expect the issue.code to be minLength. This works as expected when Group does not have the parts: "Part[]" field.
When Group does have the parts: "Part[]" field, the error changes to issue.code="union". This seems wrong. I don't think it should change the behaviour.
I understand that technically because of the invalid constraint, this value is not a match for either Field or Group, and that's why it's reporting the potential choice. But given the discriminant is correct and the structure is correct, the likelihood of this being an invalid Group seems pretty much zero.
The practical impract of this is that I was developing a form with Tanstack Form which contains some unions and the validation errors don't get correct associated with the fields because of this issue.code="union" issue.
Adding a field to a union variant which refers to the union affects errors reported for other variants.
π Search Terms
union, path, key
π§© Context
π§βπ» Repro
Playground Link
In this example, I am not validating any Groups. I'm validating a single Field whose
valueis too short. I expect theissue.codeto beminLength. This works as expected when Group does not have theparts: "Part[]"field.When Group does have the
parts: "Part[]"field, the error changes toissue.code="union". This seems wrong. I don't think it should change the behaviour.I understand that technically because of the invalid constraint, this value is not a match for either Field or Group, and that's why it's reporting the potential choice. But given the discriminant is correct and the structure is correct, the likelihood of this being an invalid Group seems pretty much zero.
The practical impract of this is that I was developing a form with Tanstack Form which contains some unions and the validation errors don't get correct associated with the fields because of this
issue.code="union"issue.