Skip to content
Onsite

TupleToUnion<T>

EasyP2Coding

Implement TupleToUnion<T>, the union of all element types of a tuple T.

Tests your type must pass

type cases = [
  Expect<Equal<TupleToUnion<[123, '456', true]>, 123 | '456' | true>>,
  Expect<Equal<TupleToUnion<[123]>, 123>>,
  Expect<Equal<TupleToUnion<[]>, never>>,
  Expect<Equal<TupleToUnion<readonly ['a', 'b']>, 'a' | 'b'>>,
]

Hints

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