types-kit.lastinunion.md
September 4, 2023 ยท View on GitHub
Home > types-kit > LastInUnion
LastInUnion type
Get the last type in a union type (important!: the result is random when you are using tsc, the correct type can only be obtained through the editor environment).
Signature:
export type LastInUnion<U> = UnionToIntersection<
U extends unknown ? (x: U) => 0 : never
> extends (x: infer L) => 0
? L
: never
References: UnionToIntersection
Example
// Expect: 2
type Foo = LastInUnion<1 | 2>
if it is necessary to output one type from overload, TS selects the last signature in the overload.