Skip to content
Onsite

Flatten<T>

MediumP2Coding

Implement Flatten<T>: flatten a tuple type that may contain nested tuples into a flat tuple of the non-tuple elements, in order.

Tests your type must pass

type cases = [
  Expect<Equal<Flatten<[]>, []>>,
  Expect<Equal<Flatten<[1, 2, 3, 4]>, [1, 2, 3, 4]>>,
  Expect<Equal<Flatten<[1, [2]]>, [1, 2]>>,
  Expect<Equal<Flatten<[1, 2, [3, 4], [[[5]]]]>, [1, 2, 3, 4, 5]>>,
  Expect<Equal<Flatten<[{ foo: 'bar'; 2: 10 }, 'foobar']>, [{ foo: 'bar'; 2: 10 }, 'foobar']>>,
  Expect<Equal<Flatten<[[], [[]]]>, []>>,
]

Hints

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