TypeScript · Exercise 1 of 5Next
Advanced
Pull Out the Item Type
Write a generic type ElementOf<T> that gives the type of the items when T is an array, and never when it is not.
ElementOf<string[]> must be string. Use infer.
What Check tests
- Your code has no type errors
ElementOf<string[]>accepts a stringElementOf<string[]>rejects a number- A non-array gives never
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.