Command Palette

Search for a command to run...

Hectal
Phase 9: Conditional and Template Literal Types
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

  1. Your code has no type errors
  2. ElementOf<string[]> accepts a string
  3. ElementOf<string[]> rejects a number
  4. 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.

Console

Nothing printed yet.