Command Palette

Search for a command to run...

Hectal
Phase 3: Type Aliases and Interfaces
TypeScript · Exercise 2 of 6 PreviousNext
Beginner

Describe a User

Fill in the interface User: a readonly number id, a text name, and an optional text nickname.

The code makes a user u and prints its nickname or a fallback. The checks try to change u.id and to create a user with no name, and expect TypeScript to refuse both.

What Check tests

  1. Your code has no type errors
  2. The console prints Asha and no nickname
  3. Changing u.id is rejected
  4. A user with a nickname is accepted
  5. A user without a name is rejected

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.