arktype
arktype copied to clipboard
Collapse common parts of union
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?