Skip to content

Custom error message for discriminated union #963

Closed

Description

@ssalbdivad

This will help avoid confusing messages where some branches are not displayed in expected.

Also need to convert domain to typeof for discrimination

Activity

  1. moved this from To do to In progress in arktypeioon May 22, 2024
  2. moved this from In progress to Planned in arktypeioon Jul 9, 2024
  3. moved this from Planned to Backlog in arktypeioon Jul 26, 2024
  4. moved this from Backlog to Planned in arktypeioon Jul 26, 2024
  5. moved this from Planned to Backlog in arktypeioon Jul 26, 2024
  6. TizzySaurus commented on Mar 6, 2025

    @TizzySaurus
    Contributor

    Of note:

    Just discovered that metadata also isn't preserved for discriminated union, meaning e.g. .describe() descriptions are lost

    import { type } from "arktype";
    
    const t = type("string<2").describe("foo")
    const t2 = t.or(type("string>=2").describe("bar")) // non-discriminated union
    console.log(t2.assert({})); // references 'foo' and 'bar' in the error
    
    const t3 = t.or(type("number").describe("baz")); // discriminated union
    console.log(t3.assert({})); // references 'string' and 'number', instead of 'foo' and 'baz'
  7. ssalbdivad commented on Nov 18, 2026

    @ssalbdivad
    MemberAuthor

    Fixed in 3.0.0-beta.0 (#1728). Try it with npm i arktype@next.

  8. moved this from Backlog to Done (merged or closed) in arktypeioon Nov 18, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    • Status
      Done (merged or closed)

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions