Command Palette

Search for a command to run...

Hectal
Phase 4: Unions, Literals and Narrowing
TypeScript · Exercise 1 of 6Next
Beginner

Only These Directions

The function move accepts any text, so a typo like "lef" gets through. Change the type Direction so only "up", "down", "left" and "right" are allowed.

The checks call move("sideways") and expect TypeScript to reject it, and call move("up") and expect it to be accepted.

What Check tests

  1. Your code has no type errors
  2. move("sideways") is rejected
  3. move("up") is accepted
  4. The console prints moving left

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.