-
Notifications
You must be signed in to change notification settings - Fork 223
Open
Labels
Description
When one passes in data that satisfies no conditions for a union
the error message is rather unhelpful. Consider the following, where we neglect to provide a target
field on the either object({})
provided to union([])
.
const { assert, object, number, string } = window.Superstruct
const { union } = window.Superstruct;
const Validation = union([
object({ documentID: string() }),
object({ formID: string() }),
]);
const data = {
target: 'DOCUMENT',
documentID: 'identifier',
}
The resulting error message looks as follows, to be contrasted with the error message against a raw object({})
:
Expected the value to satisfy a union of `object | object`, but received: [object Object]
At path: target -- Expected a value of type `never`, but received: `\"DOCUMENT\"`
Djaler, EgorPopovPP, snorremd, go-fjords-tech, snaumov and 4 more