Command Palette

Search for a command to run...

Hectal
Phase 15: TypeScript in Real Projects
TypeScript · Exercise 2 of 6 PreviousNext
Beginner

Typed routes

Write a type Route for a shop: the pages /, /cart and /checkout, and any product page /products/<something>. Then goTo(route: Route) that logs going to <route>.

Calling goTo("/chekout") (a typo) must be a type error. The program calls goTo("/cart") and goTo("/products/42").

What Check tests

  1. Your code has no type errors
  2. The program prints going to /products/42
  3. A typo in a page is rejected
  4. Any product page is accepted
  5. A made-up folder 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.