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
- Your code has no type errors
- The console prints
a 10andundefined - A number array gives
number | undefined - A text array gives
string | undefined - A number array is not a
string | undefined - 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.
Press Run to see the page.
Console
Nothing printed yet.