Skip to content

Instantly share code, notes, and snippets.

@AustinMatherne
Created September 29, 2017 05:01
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save AustinMatherne/08a7841323f234e63c3a04d7d6f0da1b to your computer and use it in GitHub Desktop.
Save AustinMatherne/08a7841323f234e63c3a04d7d6f0da1b to your computer and use it in GitHub Desktop.
Const Typed Reducer
// counter.reducer.ts
import * as CounterActions from './counter.actions';
export type Action = CounterActions.All;
export function reducer(state: number = 0, action: Action): State {
switch(action.type) {
case CounterActions.INCREMENT: {
return state + 1;
}
case CounterActions.DECREMENT: {
return state - 1;
}
case CounterActions.RESET: {
return action.payload; // typed to number
}
default: {
return state;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment