TypeScript · Exercise 6 of 6 Previous
Advanced
Loading, error and success as one type
Replace the loose Remote<T> with a discriminated union: { status: "loading" }, { status: "error"; message: string } and { status: "success"; data: T }.
Then write RemoteView: it shows Loading..., Failed: <message> or whatever render(data) returns, using a switch that ends with default: return assertNever(state);.
The checks use Remote, the ids #s-loading, #s-error and #s-success, and the text each should contain.
What Check tests
- Your code has no type errors
- A success state without data is rejected
- A success state with the wrong kind of data is rejected
- An error state without a message is rejected
- A valid error state is accepted
- The ending of RemoteView is assertNever(state)
- The three views show Loading..., Failed: boom and Hello Asha
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.
Your page
Press Run to see the page.
Console
Nothing logged yet.