Skip to content
Onsite

Permutation<T>

MediumP3Coding

Implement Permutation<T>: given a union of literal types, return a union of tuples, one for every ordering of the union's members. Permutation<never> is the empty tuple [].

Tests your type must pass

type cases = [
  Expect<Equal<Permutation<'A'>, ['A']>>,
  Expect<Equal<
    Permutation<'A' | 'B' | 'C'>,
    ['A', 'B', 'C'] | ['A', 'C', 'B'] | ['B', 'A', 'C'] | ['B', 'C', 'A'] | ['C', 'A', 'B'] | ['C', 'B', 'A']
  >>,
  Expect<Equal<Permutation<'B' | 'A' | 'C'>, Permutation<'A' | 'B' | 'C'>>>,
  Expect<Equal<Permutation<boolean>, [false, true] | [true, false]>>,
  Expect<Equal<Permutation<never>, []>>,
]

Hints

TypeScript
Run and Submit type-check your solution against the tests.