Collapsing a discriminated union - derive an umbrella type with all possible key-value combinations from the union
问题 I have a discriminated union, for example: type Union = { a: "foo", b: string, c: number } | {a: "bar", b: boolean } I need to derive a type that includes all potential properties, assigned with types that may be found on any member of Union , even if only defined on some - in my example: type CollapsedUnion = { a: "foo" | "bar", b: string | boolean, c: number | undefined } How can I make a generic that derives such collapsed unions? I need a generic that supports unions of any size. Similar