File tree 2 files changed +14
-19
lines changed
2 files changed +14
-19
lines changed Original file line number Diff line number Diff line change @@ -28,10 +28,10 @@ describe('applyMiddleware', () => {
28
28
} )
29
29
30
30
it ( 'wraps dispatch method with middleware once' , ( ) => {
31
- function test ( spyOnMethods : any ) {
32
- return ( methods : any ) => {
31
+ function test ( spyOnMethods : any ) : Middleware {
32
+ return methods => {
33
33
spyOnMethods ( methods )
34
- return ( next : Dispatch ) => ( action : Action ) => next ( action )
34
+ return next => action => next ( action )
35
35
}
36
36
}
37
37
@@ -53,8 +53,8 @@ describe('applyMiddleware', () => {
53
53
} )
54
54
55
55
it ( 'passes recursive dispatches through the middleware chain' , ( ) => {
56
- function test ( spyOnMethods : any ) {
57
- return ( ) => ( next : Dispatch ) => ( action : Action ) => {
56
+ function test ( spyOnMethods : any ) : Middleware {
57
+ return ( ) => next => action => {
58
58
spyOnMethods ( action )
59
59
return next ( action )
60
60
}
@@ -146,8 +146,7 @@ describe('applyMiddleware', () => {
146
146
}
147
147
148
148
function dummyMiddleware ( { dispatch } : MiddlewareAPI ) {
149
- return ( _next : Dispatch ) => ( action : Action ) =>
150
- dispatch ( action , testCallArgs )
149
+ return ( _next : unknown ) => ( action : any ) => dispatch ( action , testCallArgs )
151
150
}
152
151
153
152
const store = createStore (
Original file line number Diff line number Diff line change 1
- import { MiddlewareAPI , Dispatch , AnyAction } from 'redux'
1
+ import { Dispatch , Middleware } from 'redux'
2
2
3
- type ThunkAction < T extends any = any > = T extends AnyAction
4
- ? AnyAction
5
- : T extends Function
6
- ? T
7
- : never
8
-
9
- export function thunk ( { dispatch, getState } : MiddlewareAPI ) {
10
- return ( next : Dispatch ) =>
11
- < _ > ( action : ThunkAction ) =>
12
- typeof action === 'function' ? action ( dispatch , getState ) : next ( action )
13
- }
3
+ export const thunk : Middleware < {
4
+ < R > ( thunk : ( dispatch : Dispatch , getState : ( ) => any ) => R ) : R
5
+ } > =
6
+ ( { dispatch, getState } ) =>
7
+ next =>
8
+ action =>
9
+ typeof action === 'function' ? action ( dispatch , getState ) : next ( action )
You can’t perform that action at this time.
0 commit comments