Typed Redux Reducers in TypeScript 2.0
spin.atomicobject.com
spin.atomicobject.com
export type INCREMENT_COUNTER = 'App/INCREMENT_COUNTER';
export const INCREMENT_COUNTER : INCREMENT_COUNTER = 'App/INCREMENT_COUNTER';
These aren't necessary, you can use those type strings directly: export interface IncrementCounterAction = {
type: 'App/INCREMENT_COUNTER',
by: number
};
In vanilla, untyped Redux the constants are a good idea because they
give you some safety and IDE-ability. With Typescript they're just
a waste of code, since TS is going to check those type strings for you.
Cut out the middleman! switch (action.type) {
case IncrementCounterAction.type:
return state.update(...);
case DeccrementCounterAction.type:
return state.update(...);
....
}