@@ -73,17 +73,12 @@ export type WithMiddlewareType<T extends Middleware<any, any, any>> = {
73
73
export type MiddlewarePhase = 'beforeReducer' | 'afterReducer'
74
74
75
75
export type When = MiddlewarePhase | 'both' | undefined
76
- type WhenFromOptions < O extends ActionListenerOptions > =
77
- O extends ActionListenerOptions ? O [ 'when' ] : never
78
76
79
77
/**
80
78
* @alpha
81
79
*/
82
- export interface ActionListenerMiddlewareAPI <
83
- S ,
84
- D extends Dispatch < AnyAction > ,
85
- O extends ActionListenerOptions
86
- > extends MiddlewareAPI < D , S > {
80
+ export interface ActionListenerMiddlewareAPI < S , D extends Dispatch < AnyAction > >
81
+ extends MiddlewareAPI < D , S > {
87
82
getOriginalState : ( ) => S
88
83
unsubscribe ( ) : void
89
84
condition : ConditionFunction < AnyAction , S >
@@ -98,9 +93,8 @@ export interface ActionListenerMiddlewareAPI<
98
93
export type ActionListener <
99
94
A extends AnyAction ,
100
95
S ,
101
- D extends Dispatch < AnyAction > ,
102
- O extends ActionListenerOptions
103
- > = ( action : A , api : ActionListenerMiddlewareAPI < S , D , O > ) => void
96
+ D extends Dispatch < AnyAction >
97
+ > = ( action : A , api : ActionListenerMiddlewareAPI < S , D > ) => void
104
98
105
99
export interface ListenerErrorHandler {
106
100
( error : unknown ) : void
@@ -126,14 +120,12 @@ export interface CreateListenerMiddlewareOptions<ExtraArgument = unknown> {
126
120
export interface AddListenerAction <
127
121
A extends AnyAction ,
128
122
S ,
129
- D extends Dispatch < AnyAction > ,
130
- O extends ActionListenerOptions
123
+ D extends Dispatch < AnyAction >
131
124
> {
132
125
type : 'actionListenerMiddleware/add'
133
126
payload : {
134
127
type : string
135
- listener : ActionListener < A , S , D , O >
136
- options ?: O
128
+ listener : ActionListener < A , S , D >
137
129
}
138
130
}
139
131
@@ -166,7 +158,7 @@ export const addListenerAction = createAction(
166
158
'actionListenerMiddleware/add' ,
167
159
function prepare (
168
160
typeOrActionCreator : string | TypedActionCreator < string > ,
169
- listener : ActionListener < any , any , any , any > ,
161
+ listener : ActionListener < any , any , any > ,
170
162
options ?: ActionListenerOptions
171
163
) {
172
164
const type =
@@ -185,7 +177,7 @@ export const addListenerAction = createAction(
185
177
) as BaseActionCreator <
186
178
{
187
179
type : string
188
- listener : ActionListener < any , any , any , any >
180
+ listener : ActionListener < any , any , any >
189
181
options : ActionListenerOptions
190
182
} ,
191
183
'actionListenerMiddleware/add'
@@ -197,15 +189,15 @@ export const addListenerAction = createAction(
197
189
O extends ActionListenerOptions
198
190
> (
199
191
actionCreator : C ,
200
- listener : ActionListener < ReturnType < C > , S , D , O > ,
192
+ listener : ActionListener < ReturnType < C > , S , D > ,
201
193
options ?: O
202
- ) : AddListenerAction < ReturnType < C > , S , D , O >
194
+ ) : AddListenerAction < ReturnType < C > , S , D >
203
195
204
196
< S , D extends Dispatch , O extends ActionListenerOptions > (
205
197
type : string ,
206
- listener : ActionListener < AnyAction , S , D , O > ,
198
+ listener : ActionListener < AnyAction , S , D > ,
207
199
options ?: O
208
- ) : AddListenerAction < AnyAction , S , D , O >
200
+ ) : AddListenerAction < AnyAction , S , D >
209
201
}
210
202
211
203
interface RemoveListenerAction <
@@ -216,7 +208,7 @@ interface RemoveListenerAction<
216
208
type : 'actionListenerMiddleware/remove'
217
209
payload : {
218
210
type : string
219
- listener : ActionListener < A , S , D , any >
211
+ listener : ActionListener < A , S , D >
220
212
}
221
213
}
222
214
@@ -227,7 +219,7 @@ export const removeListenerAction = createAction(
227
219
'actionListenerMiddleware/remove' ,
228
220
function prepare (
229
221
typeOrActionCreator : string | TypedActionCreator < string > ,
230
- listener : ActionListener < any , any , any , any >
222
+ listener : ActionListener < any , any , any >
231
223
) {
232
224
const type =
233
225
typeof typeOrActionCreator === 'string'
@@ -242,17 +234,17 @@ export const removeListenerAction = createAction(
242
234
}
243
235
}
244
236
) as BaseActionCreator <
245
- { type : string ; listener : ActionListener < any , any , any , any > } ,
237
+ { type : string ; listener : ActionListener < any , any , any > } ,
246
238
'actionListenerMiddleware/remove'
247
239
> & {
248
240
< C extends TypedActionCreator < any > , S , D extends Dispatch > (
249
241
actionCreator : C ,
250
- listener : ActionListener < ReturnType < C > , S , D , any >
242
+ listener : ActionListener < ReturnType < C > , S , D >
251
243
) : RemoveListenerAction < ReturnType < C > , S , D >
252
244
253
245
< S , D extends Dispatch > (
254
246
type : string ,
255
- listener : ActionListener < AnyAction , S , D , any >
247
+ listener : ActionListener < AnyAction , S , D >
256
248
) : RemoveListenerAction < AnyAction , S , D >
257
249
}
258
250
@@ -273,7 +265,7 @@ export function createActionListenerMiddleware<
273
265
> ( middlewareOptions : CreateListenerMiddlewareOptions < ExtraArgument > = { } ) {
274
266
type ListenerEntry = ActionListenerOptions & {
275
267
id : string
276
- listener : ActionListener < any , S , D , any >
268
+ listener : ActionListener < any , S , D >
277
269
unsubscribe : ( ) => void
278
270
type ?: string
279
271
predicate : ListenerPredicate < any , any >
@@ -367,13 +359,13 @@ export function createActionListenerMiddleware<
367
359
O extends ActionListenerOptions
368
360
> (
369
361
actionCreator : C ,
370
- listener : ActionListener < ReturnType < C > , S , D , O > ,
362
+ listener : ActionListener < ReturnType < C > , S , D > ,
371
363
options ?: O
372
364
) : Unsubscribe
373
365
// eslint-disable-next-line no-redeclare
374
366
function addListener < T extends string , O extends ActionListenerOptions > (
375
367
type : T ,
376
- listener : ActionListener < Action < T > , S , D , O > ,
368
+ listener : ActionListener < Action < T > , S , D > ,
377
369
options ?: O
378
370
) : Unsubscribe
379
371
// eslint-disable-next-line no-redeclare
@@ -383,7 +375,7 @@ export function createActionListenerMiddleware<
383
375
O extends ActionListenerOptions
384
376
> (
385
377
matcher : M ,
386
- listener : ActionListener < GuardedType < M > , S , D , O > ,
378
+ listener : ActionListener < GuardedType < M > , S , D > ,
387
379
options ?: O
388
380
) : Unsubscribe
389
381
// eslint-disable-next-line no-redeclare
@@ -393,7 +385,7 @@ export function createActionListenerMiddleware<
393
385
O extends ActionListenerOptions
394
386
> (
395
387
matcher : M ,
396
- listener : ActionListener < AnyAction , S , D , O > ,
388
+ listener : ActionListener < AnyAction , S , D > ,
397
389
options ?: O
398
390
) : Unsubscribe
399
391
// eslint-disable-next-line no-redeclare
@@ -402,7 +394,7 @@ export function createActionListenerMiddleware<
402
394
| string
403
395
| TypedActionCreator < any >
404
396
| ListenerPredicate < any , any > ,
405
- listener : ActionListener < AnyAction , S , D , any > ,
397
+ listener : ActionListener < AnyAction , S , D > ,
406
398
options ?: ActionListenerOptions
407
399
) : Unsubscribe {
408
400
let predicate : ListenerPredicate < any , any >
@@ -448,17 +440,17 @@ export function createActionListenerMiddleware<
448
440
449
441
function removeListener < C extends TypedActionCreator < any > > (
450
442
actionCreator : C ,
451
- listener : ActionListener < ReturnType < C > , S , D , any >
443
+ listener : ActionListener < ReturnType < C > , S , D >
452
444
) : boolean
453
445
// eslint-disable-next-line no-redeclare
454
446
function removeListener (
455
447
type : string ,
456
- listener : ActionListener < AnyAction , S , D , any >
448
+ listener : ActionListener < AnyAction , S , D >
457
449
) : boolean
458
450
// eslint-disable-next-line no-redeclare
459
451
function removeListener (
460
452
typeOrActionCreator : string | TypedActionCreator < any > ,
461
- listener : ActionListener < AnyAction , S , D , any >
453
+ listener : ActionListener < AnyAction , S , D >
462
454
) : boolean {
463
455
const type =
464
456
typeof typeOrActionCreator === 'string'
0 commit comments