types-kit.uniontotuple.md

September 4, 2023 ยท View on GitHub

Home > types-kit > UnionToTuple

UnionToTuple type

Convert union type to a tuple.

Signature:

export type UnionToTuple<U> = [U] extends [never] // no type
  ? []
  : [...UnionToTuple<Exclude<U, LastInUnion<U>>>, LastInUnion<U>]

References: UnionToTuple, LastInUnion

Example

// Expect: ['3', '1', '2']
type Foo = UnionToTuple<'3' | '1' | '2'>

Contents

  1. 1UnionToTuple type
  2. 2Example