Skip to content

Collapse common parts of union #751

Closed

Description

@ssalbdivad

You can reduce a union of two structures, neither of which is a subtype of the other, iff there exists some key K such that K is present in both structures and such that the set of entries other than K is identical for both structures, both in terms of keys and values.

This would allow the following types to reduce to equivalent:

const t = type({ a: "string" }, "|", { a: "number" });

const u = type({
  a: "string|number",
});

Also if you think about how 1<number<10|10<=number<100 works, it is the only case I can think of where despite the two branches being disjoint, they can be reduced when unioned. Perhaps this could be handled with the same underlying logic?

Activity

  1. moved this from To do to Backlog in arktypeioon May 10, 2023
  2. changed the title [-]Collpase common parts of union[/-] [+]Collapse common parts of union[/+] on Nov 26, 2023
  3. ssalbdivad commented on Nov 18, 2026

    @ssalbdivad
    MemberAuthor

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

  4. 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