Command Palette

Search for a command to run...

Hectal
Phase 5: Arrays, Tuples, Enums and Special Types
TypeScript · Exercise 5 of 6 PreviousNext
Intermediate

A Function That Never Returns

findUser should return a User, or stop the program with a clear message. TypeScript complains that user might still be undefined at return user, because it doesn't know fail never comes back.

Give fail the right return type so the compiler understands. The checks also assign fail("x") to a never variable.

What Check tests

  1. Your code has no type errors
  2. fail has the type never
  3. The console prints Ravi
  4. The console prints No user 9

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.