Command Palette

Search for a command to run...

Hectal
Phase 7: Generics
TypeScript · Exercise 1 of 6Next
Beginner

Make first Generic

first returns the first item of an array, but its signature uses unknown, so the caller gets unknown back and can't use the value without checking it.

Make first generic so the result follows the array: an array of numbers gives number | undefined, an array of texts gives string | undefined. Don't use any.

What Check tests

  1. Your code has no type errors
  2. The console prints a 10 and undefined
  3. A number array gives number | undefined
  4. A text array gives string | undefined
  5. A number array is not a string | undefined
  6. No any

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.