Intermediate
A counter reducer with typed actions
Make Action a discriminated union with four members: increment, decrement, reset and add, where only add carries an amount: number. Then write the reducer with a switch and finish it with default: return assertNever(action);.
The checks use the ids #inc (+1), #dec (-1), #add (+10), #reset and #count. The buttons are already in the starter; add the #dec button yourself.
What Check tests
- Your code has no type errors
- An unknown action type is rejected
- An add action without an amount is rejected
- A valid add action is accepted
- The reducer ends with assertNever(action)
- The buttons change #count: +1, +10, -1, then reset
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.