Home > types-kit > LastInUnion
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
: neverReferences: UnionToIntersection
// 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.