File tree Expand file tree Collapse file tree 1 file changed +24
-0
lines changed
playground/src/features/counters Expand file tree Collapse file tree 1 file changed +24
-0
lines changed Original file line number Diff line number Diff line change 1+ import { action , ActionType } from 'typesafe-actions' ;
2+
3+ import { Dispatch , ActionCreatorsMapObject } from 'redux' ;
4+ import * as actions from './actions' ;
5+
6+ // CLASSIC API
7+ export const thunkIncrement = ( ) => ( dispatch : Dispatch ) =>
8+ dispatch ( action ( 'THUNK_INCREMENT' ) ) ;
9+ export const thunkAdd = ( amount : number ) => ( dispatch : Dispatch ) =>
10+ dispatch ( action ( 'THUNK_ADD' , amount ) ) ;
11+
12+ type ThunkActionType < M extends ActionCreatorsMapObject < any > > = ActionType <
13+ {
14+ [ N in keyof M ] : ReturnType < M [ N ] > extends (
15+ dispatch : Dispatch
16+ ) => { type : string }
17+ ? ( ...args : Parameters < M [ N ] > ) => ReturnType < ReturnType < M [ N ] > >
18+ : M [ N ]
19+ }
20+ > ;
21+
22+ const thunkActions = { thunkIncrement, thunkAdd, ...actions } ;
23+ export type Action = ThunkActionType < typeof thunkActions > ;
24+ // type Action = EmptyAction<"THUNK_INCREMENT"> | PayloadAction<"THUNK_ADD", number> | EmptyAction<"counters/INCREMENT"> | PayloadAction<"counters/ADD", number>
You can’t perform that action at this time.
0 commit comments