Closed
Description
Would be nice to see this typescript library add the StrictUnion
generic type
type UnionKeys<T> = T extends any ? keyof T : never;
type StrictUnionHelper<T, TAll> = T extends any ? T & Partial<Record<Exclude<UnionKeys<TAll>, keyof T>, never>> : never;
type StrictUnion<T> = StrictUnionHelper<T, T>
type A = { a: number }
type B = { b: number }
const unionList: Array<A | B> = [{ a: 1 }, { b: 2 }]
const unionListInvalid: Array<A | B> = [{ a: 1 }, { b: 2 }, { a: 1, b: 2 }]
// ^ not actually invalid
const strictUnionList: Array<StrictUnion<A | B>> = [{ a: 1 }, { b: 2 }]
const strictUnionListInvalid: Array<StrictUnion<A | B>> = [{ a: 1 }, { b: 2 }, { a: 1, b: 2 }]
// ^ invalid as expected
Metadata
Metadata
Assignees
Labels
No labels