Skip to content

Union Error Message #831

@67726e

Description

@67726e

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\"`

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions