Skip to content

Latest commit

 

History

History
28 lines (19 loc) · 807 Bytes

File metadata and controls

28 lines (19 loc) · 807 Bytes

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.