Last active
September 20, 2019 03:22
-
-
Save carlrip/91364da38272965b0c8edef47f9843dd to your computer and use it in GitHub Desktop.
Switch with never type
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| const reducer = (state: State, action: Actions): State => { | |
| switch (action.type) { | |
| case "increment": | |
| return { count: state.count + action.incrementStep }; | |
| case "decrement": | |
| return { count: state.count - action.decrementStep }; | |
| default: | |
| neverReached(action); | |
| } | |
| }; | |
| const neverReached = (never: never) => {}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment