@@ -116,8 +116,11 @@ export interface ForkedTask<T> {
116
116
/**
117
117
* @alpha
118
118
*/
119
- export interface ActionListenerMiddlewareAPI < S , D extends Dispatch < AnyAction > >
120
- extends MiddlewareAPI < D , S > {
119
+ export interface ActionListenerMiddlewareAPI <
120
+ S ,
121
+ D extends Dispatch < AnyAction > ,
122
+ ExtraArgument = unknown
123
+ > extends MiddlewareAPI < D , S > {
121
124
/**
122
125
* Returns the store state as it existed when the action was originally dispatched, _before_ the reducers ran.
123
126
*
@@ -171,7 +174,7 @@ export interface ActionListenerMiddlewareAPI<S, D extends Dispatch<AnyAction>>
171
174
*/
172
175
pause < M > ( promise : Promise < M > ) : Promise < M >
173
176
// TODO Figure out how to pass this through the other types correctly
174
- extra : unknown
177
+ extra : ExtraArgument
175
178
}
176
179
177
180
/**
@@ -180,8 +183,12 @@ export interface ActionListenerMiddlewareAPI<S, D extends Dispatch<AnyAction>>
180
183
export type ActionListener <
181
184
A extends AnyAction ,
182
185
S ,
183
- D extends Dispatch < AnyAction >
184
- > = ( action : A , api : ActionListenerMiddlewareAPI < S , D > ) => void | Promise < void >
186
+ D extends Dispatch < AnyAction > ,
187
+ ExtraArgument = unknown
188
+ > = (
189
+ action : A ,
190
+ api : ActionListenerMiddlewareAPI < S , D , ExtraArgument >
191
+ ) => void | Promise < void >
185
192
186
193
export interface ListenerErrorHandler {
187
194
( error : unknown ) : void
@@ -261,7 +268,8 @@ export interface TakePattern<State> {
261
268
export interface AddListenerOverloads <
262
269
Return ,
263
270
S = unknown ,
264
- D extends Dispatch = ThunkDispatch < S , unknown , AnyAction >
271
+ D extends Dispatch = ThunkDispatch < S , unknown , AnyAction > ,
272
+ ExtraArgument = unknown
265
273
> {
266
274
/** Accepts a "listener predicate" that is also a TS type predicate for the action*/
267
275
< MA extends AnyAction , LP extends ListenerPredicate < MA , S > > (
@@ -270,7 +278,12 @@ export interface AddListenerOverloads<
270
278
type ?: never
271
279
matcher ?: never
272
280
predicate : LP
273
- listener : ActionListener < ListenerPredicateGuardedActionType < LP > , S , D >
281
+ listener : ActionListener <
282
+ ListenerPredicateGuardedActionType < LP > ,
283
+ S ,
284
+ D ,
285
+ ExtraArgument
286
+ >
274
287
} & ActionListenerOptions
275
288
) : Return
276
289
@@ -281,7 +294,7 @@ export interface AddListenerOverloads<
281
294
type ?: never
282
295
matcher ?: never
283
296
predicate ?: never
284
- listener : ActionListener < ReturnType < C > , S , D >
297
+ listener : ActionListener < ReturnType < C > , S , D , ExtraArgument >
285
298
} & ActionListenerOptions
286
299
) : Return
287
300
@@ -292,7 +305,7 @@ export interface AddListenerOverloads<
292
305
type : T
293
306
matcher ?: never
294
307
predicate ?: never
295
- listener : ActionListener < Action < T > , S , D >
308
+ listener : ActionListener < Action < T > , S , D , ExtraArgument >
296
309
} & ActionListenerOptions
297
310
) : Return
298
311
@@ -303,7 +316,7 @@ export interface AddListenerOverloads<
303
316
type ?: never
304
317
matcher : M
305
318
predicate ?: never
306
- listener : ActionListener < GuardedType < M > , S , D >
319
+ listener : ActionListener < GuardedType < M > , S , D , ExtraArgument >
307
320
} & ActionListenerOptions
308
321
) : Return
309
322
@@ -314,7 +327,7 @@ export interface AddListenerOverloads<
314
327
type ?: never
315
328
matcher ?: never
316
329
predicate : LP
317
- listener : ActionListener < AnyAction , S , D >
330
+ listener : ActionListener < AnyAction , S , D , ExtraArgument >
318
331
} & ActionListenerOptions
319
332
) : Return
320
333
}
@@ -340,10 +353,11 @@ export interface RemoveListenerAction<
340
353
export type TypedAddListenerAction <
341
354
S ,
342
355
D extends Dispatch < AnyAction > = ThunkDispatch < S , unknown , AnyAction > ,
356
+ ExtraArgument = unknown ,
343
357
Payload = ListenerEntry < S , D > ,
344
358
T extends string = 'actionListenerMiddleware/add'
345
359
> = BaseActionCreator < Payload , T > &
346
- AddListenerOverloads < PayloadAction < Payload , T > , S , D >
360
+ AddListenerOverloads < PayloadAction < Payload , T > , S , D , ExtraArgument >
347
361
348
362
/** A "pre-typed" version of `removeListenerAction`, so the listener args are well-typed */
349
363
export type TypedRemoveListenerAction <
@@ -357,8 +371,9 @@ export type TypedRemoveListenerAction<
357
371
/** A "pre-typed" version of `middleware.addListener`, so the listener args are well-typed */
358
372
export type TypedAddListener <
359
373
S ,
360
- D extends Dispatch < AnyAction > = ThunkDispatch < S , unknown , AnyAction >
361
- > = AddListenerOverloads < Unsubscribe , S , D >
374
+ D extends Dispatch < AnyAction > = ThunkDispatch < S , unknown , AnyAction > ,
375
+ ExtraArgument = unknown
376
+ > = AddListenerOverloads < Unsubscribe , S , D , ExtraArgument >
362
377
363
378
/** A "pre-typed" version of `middleware.removeListener`, so the listener args are well-typed */
364
379
export type TypedRemoveListener <
0 commit comments