Skip to content

Commit

Permalink
fix: generalize TActionCreator generic type in createHandlerMap
Browse files Browse the repository at this point in the history
fix #128
  • Loading branch information
Mohammad Hasani committed Dec 6, 2019
1 parent 14b4cba commit a7dd90a
Showing 1 changed file with 6 additions and 9 deletions.
15 changes: 6 additions & 9 deletions src/create-handler-map.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ export type InferNextStateFromHandlerMap<
> = THandlerMap extends HandlerMap<any, any, infer T> ? T : never

export type CreateHandlerMap<TPrevState> = <
TActionCreator extends ActionCreator<string>,
TActionCreator extends ActionCreator<any>,
TNextState extends TPrevState,
TAction extends AnyAction = TActionCreator extends (...args: any[]) => infer T
? T
Expand All @@ -37,7 +37,7 @@ export type CreateHandlerMap<TPrevState> = <
* createHandlerMap([increment, increase], (state: number) => state + 1)
*/
export function createHandlerMap<
TActionCreator extends ActionCreator<string>,
TActionCreator extends ActionCreator<any>,
TPrevState,
TNextState extends TPrevState,
TAction extends AnyAction = TActionCreator extends (...args: any[]) => infer T
Expand All @@ -49,11 +49,8 @@ export function createHandlerMap<
) {
return (Array.isArray(actionCreators) ? actionCreators : [actionCreators])
.map(getType)
.reduce<HandlerMap<TPrevState, TAction, TNextState>>(
(acc, type) => {
acc[type] = handler
return acc
},
{} as any
)
.reduce<HandlerMap<TPrevState, TAction, TNextState>>((acc, type) => {
acc[type] = handler
return acc
}, {} as any)
}

0 comments on commit a7dd90a

Please sign in to comment.