Command Palette

Search for a command to run...

Hectal
Phase 16: Advanced TypeScript
TypeScript · Exercise 3 of 6 PreviousNext
Advanced

Type the parameters of a route string

Write Params<S extends string> that turns a route like "/users/:id/posts/:postId" into the union "id" | "postId". A route with no : parts gives never.

Then complete url(path, params) so params must have exactly those keys (use Record<Params<S>, string>). It replaces each :name in the path with the value and returns the result.

What Check tests

  1. Your code has no type errors
  2. The URL is built
  3. A correct call is accepted
  4. A wrong key is rejected
  5. A missing key 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.