Tagged unions are indeed pretty helpful for Redux reducers. One thing
to note is that you can actually skip some code here as well. Specifically,
the constant definitions:
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!
I believe you can, though I haven't tried it. Typescript will actually give you completion support for plain strings inside that switch statement, which is normally what I go with.
4 comments
[ 2.9 ms ] story [ 16.1 ms ] thread