Command Palette

Search for a command to run...

Hectal
Phase 3: Type Aliases and Interfaces
TypeScript · Exercise 4 of 6 PreviousNext
Intermediate

Accept Books Too

label takes anything with a name. The last line passes a book object with an extra pages member, and TypeScript reports an excess property error on that fresh literal.

Change only the parameter type of label so that books with an optional pages count are accepted, while an object with some other unknown member (like colour) is still rejected.

What Check tests

  1. Your code has no type errors
  2. The console prints PEN and BOOK
  3. A book with a page count is accepted
  4. An unknown member is still 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.