Intermediate
A client typed by the contract
A Contract lists two routes with their request and response types, and handlers implements them. Write call<R extends Route>(route: R, request: Contract[R]["request"]) that returns Contract[R]["response"] by running the matching handler.
The route name must decide the types: call("GET /count", { n: "x" }) has to be a type error, and the result of call("GET /count", { n: 2 }) has to be a number.
What Check tests
- Your code has no type errors
- The program prints 42 and Hello, Asha
- A wrong request type is rejected
- An unknown route is rejected
- The count result is a number
- The greet result is not a number
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.
Press Run to see the page.
Console
Nothing printed yet.