1
- import { createStore , applyMiddleware } from '../'
1
+ import {
2
+ createStore ,
3
+ applyMiddleware ,
4
+ Middleware ,
5
+ Dispatch ,
6
+ AnyAction ,
7
+ Action
8
+ } from '..'
2
9
import * as reducers from './helpers/reducers'
3
10
import { addTodo , addTodoAsync , addTodoIfEmpty } from './helpers/actionCreators'
4
11
import { thunk } from './helpers/middleware'
@@ -51,7 +58,11 @@ describe('applyMiddleware', () => {
51
58
const spy = jest . fn ( )
52
59
const store = applyMiddleware ( test ( spy ) , thunk ) ( createStore ) ( reducers . todos )
53
60
54
- return store . dispatch ( addTodoAsync ( 'Use Redux' ) ) . then ( ( ) => {
61
+ // the typing for redux-thunk is super complex, so we will use an as unknown hack
62
+ const dispatchedValue = ( store . dispatch (
63
+ addTodoAsync ( 'Use Redux' )
64
+ ) as unknown ) as Promise < void >
65
+ return dispatchedValue . then ( ( ) => {
55
66
expect ( spy . mock . calls . length ) . toEqual ( 2 )
56
67
} )
57
68
} )
@@ -87,7 +98,11 @@ describe('applyMiddleware', () => {
87
98
}
88
99
] )
89
100
90
- store . dispatch ( addTodoAsync ( 'Maybe' ) ) . then ( ( ) => {
101
+ // the typing for redux-thunk is super complex, so we will use an "as unknown" hack
102
+ const dispatchedValue = ( store . dispatch (
103
+ addTodoAsync ( 'Maybe' )
104
+ ) as unknown ) as Promise < void >
105
+ dispatchedValue . then ( ( ) => {
91
106
expect ( store . getState ( ) ) . toEqual ( [
92
107
{
93
108
id : 1 ,
@@ -110,8 +125,16 @@ describe('applyMiddleware', () => {
110
125
const spy = jest . fn ( )
111
126
const testCallArgs = [ 'test' ]
112
127
113
- function multiArgMiddleware ( ) {
114
- return next => ( action , callArgs ) => {
128
+ interface MultiDispatch < A extends Action = AnyAction > {
129
+ < T extends A > ( action : T , extraArg ?: string [ ] ) : T
130
+ }
131
+
132
+ const multiArgMiddleware : Middleware <
133
+ MultiDispatch ,
134
+ any ,
135
+ MultiDispatch
136
+ > = _store => {
137
+ return next => ( action , callArgs ?: any ) => {
115
138
if ( Array . isArray ( callArgs ) ) {
116
139
return action ( ...callArgs )
117
140
}
0 commit comments