Command Palette

Search for a command to run...

Hectal
Phase 16: Advanced TypeScript
TypeScript · Exercise 2 of 6 PreviousNext
Advanced

Build First, Last and Concat

Write three generic types: First<T extends unknown[]>, Last<T extends unknown[]> and Concat<A extends unknown[], B extends unknown[]>.

First<[1, 2, 3]> is 1, Last<[1, 2, 3]> is 3, Concat<[1], [2, 3]> is [1, 2, 3]. For an empty tuple, First and Last are never.

What Check tests

  1. Your code has no type errors
  2. First picks the first element
  3. First is not the second element
  4. Last picks the last element
  5. Last of an empty tuple is never
  6. Concat joins in order

Stuck? One hint at a time

The solution unlocks after your first Check. Try first: that is where the learning happens.

Runs in your browser. Your code is saved here.

Console

Nothing printed yet.