1
- import { Store , Middleware } from 'redux' ;
2
- import thunk , { ThunkAction } from '../index' ;
1
+ import { createStore , applyMiddleware } from 'redux' ;
2
+ import thunk , { ThunkAction } from '../index' ;
3
3
4
4
type State = {
5
- foo : string
5
+ foo : string ;
6
6
} ;
7
7
8
8
type Actions = { type : 'FOO' } ;
9
9
10
- declare const store : Store < State , Actions > ;
10
+ function fakeReducer ( state : State , action : Actions ) : State {
11
+ return state ;
12
+ }
13
+
14
+ const store = createStore ( fakeReducer , applyMiddleware ( thunk ) ) ;
11
15
12
16
store . dispatch ( dispatch => {
13
- dispatch ( { type : 'FOO' } ) ;
17
+ dispatch ( { type : 'FOO' } ) ;
14
18
} ) ;
15
19
16
20
function testGetState ( ) : ThunkAction < void , State , { } , Actions > {
@@ -22,20 +26,27 @@ function testGetState(): ThunkAction<void, State, {}, Actions> {
22
26
23
27
store . dispatch ( testGetState ( ) ) ;
24
28
25
- const middleware : Middleware = thunk . withExtraArgument ( 'bar' ) ;
29
+ const storeThunkArg = createStore (
30
+ fakeReducer ,
31
+ applyMiddleware ( thunk . withExtraArgument ( 'bar' ) )
32
+ ) ;
26
33
27
- store . dispatch ( ( dispatch , getState , extraArg ) => {
34
+ storeThunkArg . dispatch ( ( dispatch , getState , extraArg ) => {
35
+ const bar : string = extraArg ;
28
36
console . log ( extraArg ) ;
29
37
} ) ;
30
38
31
- const thunkAction : ThunkAction < void , { foo : string } , { bar : number } > =
32
- ( dispatch , getState , extraArg ) => {
33
- const foo : string = getState ( ) . foo ;
34
- const bar : number = extraArg . bar ;
39
+ const thunkAction : ThunkAction < void , State , { bar : number } , Actions > = (
40
+ dispatch ,
41
+ getState ,
42
+ extraArg
43
+ ) => {
44
+ const foo : string = getState ( ) . foo ;
45
+ const bar : number = extraArg . bar ;
35
46
36
- dispatch ( { type : 'FOO' } ) ;
37
- } ;
47
+ dispatch ( { type : 'FOO' } ) ;
48
+ } ;
38
49
39
- const thunkActionDispatchOnly : ThunkAction < void , { } , { } > = dispatch => {
40
- dispatch ( { type : 'FOO' } ) ;
50
+ const thunkActionDispatchOnly : ThunkAction < void , { } , { } , Actions > = dispatch => {
51
+ dispatch ( { type : 'FOO' } ) ;
41
52
} ;
0 commit comments