Skip to content

Instantly share code, notes, and snippets.

@carlrip
Last active September 20, 2019 03:22
Show Gist options
  • Save carlrip/91364da38272965b0c8edef47f9843dd to your computer and use it in GitHub Desktop.
Save carlrip/91364da38272965b0c8edef47f9843dd to your computer and use it in GitHub Desktop.
Switch with never type
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