Skip to content

Commit 6160877

Browse files
committed
Remove unneeded Options generic
1 parent 37db123 commit 6160877

File tree

1 file changed

+26
-34
lines changed
  • packages/action-listener-middleware/src

1 file changed

+26
-34
lines changed

packages/action-listener-middleware/src/index.ts

Lines changed: 26 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -73,17 +73,12 @@ export type WithMiddlewareType<T extends Middleware<any, any, any>> = {
7373
export type MiddlewarePhase = 'beforeReducer' | 'afterReducer'
7474

7575
export type When = MiddlewarePhase | 'both' | undefined
76-
type WhenFromOptions<O extends ActionListenerOptions> =
77-
O extends ActionListenerOptions ? O['when'] : never
7876

7977
/**
8078
* @alpha
8179
*/
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> {
8782
getOriginalState: () => S
8883
unsubscribe(): void
8984
condition: ConditionFunction<AnyAction, S>
@@ -98,9 +93,8 @@ export interface ActionListenerMiddlewareAPI<
9893
export type ActionListener<
9994
A extends AnyAction,
10095
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
10498

10599
export interface ListenerErrorHandler {
106100
(error: unknown): void
@@ -126,14 +120,12 @@ export interface CreateListenerMiddlewareOptions<ExtraArgument = unknown> {
126120
export interface AddListenerAction<
127121
A extends AnyAction,
128122
S,
129-
D extends Dispatch<AnyAction>,
130-
O extends ActionListenerOptions
123+
D extends Dispatch<AnyAction>
131124
> {
132125
type: 'actionListenerMiddleware/add'
133126
payload: {
134127
type: string
135-
listener: ActionListener<A, S, D, O>
136-
options?: O
128+
listener: ActionListener<A, S, D>
137129
}
138130
}
139131

@@ -166,7 +158,7 @@ export const addListenerAction = createAction(
166158
'actionListenerMiddleware/add',
167159
function prepare(
168160
typeOrActionCreator: string | TypedActionCreator<string>,
169-
listener: ActionListener<any, any, any, any>,
161+
listener: ActionListener<any, any, any>,
170162
options?: ActionListenerOptions
171163
) {
172164
const type =
@@ -185,7 +177,7 @@ export const addListenerAction = createAction(
185177
) as BaseActionCreator<
186178
{
187179
type: string
188-
listener: ActionListener<any, any, any, any>
180+
listener: ActionListener<any, any, any>
189181
options: ActionListenerOptions
190182
},
191183
'actionListenerMiddleware/add'
@@ -197,15 +189,15 @@ export const addListenerAction = createAction(
197189
O extends ActionListenerOptions
198190
>(
199191
actionCreator: C,
200-
listener: ActionListener<ReturnType<C>, S, D, O>,
192+
listener: ActionListener<ReturnType<C>, S, D>,
201193
options?: O
202-
): AddListenerAction<ReturnType<C>, S, D, O>
194+
): AddListenerAction<ReturnType<C>, S, D>
203195

204196
<S, D extends Dispatch, O extends ActionListenerOptions>(
205197
type: string,
206-
listener: ActionListener<AnyAction, S, D, O>,
198+
listener: ActionListener<AnyAction, S, D>,
207199
options?: O
208-
): AddListenerAction<AnyAction, S, D, O>
200+
): AddListenerAction<AnyAction, S, D>
209201
}
210202

211203
interface RemoveListenerAction<
@@ -216,7 +208,7 @@ interface RemoveListenerAction<
216208
type: 'actionListenerMiddleware/remove'
217209
payload: {
218210
type: string
219-
listener: ActionListener<A, S, D, any>
211+
listener: ActionListener<A, S, D>
220212
}
221213
}
222214

@@ -227,7 +219,7 @@ export const removeListenerAction = createAction(
227219
'actionListenerMiddleware/remove',
228220
function prepare(
229221
typeOrActionCreator: string | TypedActionCreator<string>,
230-
listener: ActionListener<any, any, any, any>
222+
listener: ActionListener<any, any, any>
231223
) {
232224
const type =
233225
typeof typeOrActionCreator === 'string'
@@ -242,17 +234,17 @@ export const removeListenerAction = createAction(
242234
}
243235
}
244236
) as BaseActionCreator<
245-
{ type: string; listener: ActionListener<any, any, any, any> },
237+
{ type: string; listener: ActionListener<any, any, any> },
246238
'actionListenerMiddleware/remove'
247239
> & {
248240
<C extends TypedActionCreator<any>, S, D extends Dispatch>(
249241
actionCreator: C,
250-
listener: ActionListener<ReturnType<C>, S, D, any>
242+
listener: ActionListener<ReturnType<C>, S, D>
251243
): RemoveListenerAction<ReturnType<C>, S, D>
252244

253245
<S, D extends Dispatch>(
254246
type: string,
255-
listener: ActionListener<AnyAction, S, D, any>
247+
listener: ActionListener<AnyAction, S, D>
256248
): RemoveListenerAction<AnyAction, S, D>
257249
}
258250

@@ -273,7 +265,7 @@ export function createActionListenerMiddleware<
273265
>(middlewareOptions: CreateListenerMiddlewareOptions<ExtraArgument> = {}) {
274266
type ListenerEntry = ActionListenerOptions & {
275267
id: string
276-
listener: ActionListener<any, S, D, any>
268+
listener: ActionListener<any, S, D>
277269
unsubscribe: () => void
278270
type?: string
279271
predicate: ListenerPredicate<any, any>
@@ -367,13 +359,13 @@ export function createActionListenerMiddleware<
367359
O extends ActionListenerOptions
368360
>(
369361
actionCreator: C,
370-
listener: ActionListener<ReturnType<C>, S, D, O>,
362+
listener: ActionListener<ReturnType<C>, S, D>,
371363
options?: O
372364
): Unsubscribe
373365
// eslint-disable-next-line no-redeclare
374366
function addListener<T extends string, O extends ActionListenerOptions>(
375367
type: T,
376-
listener: ActionListener<Action<T>, S, D, O>,
368+
listener: ActionListener<Action<T>, S, D>,
377369
options?: O
378370
): Unsubscribe
379371
// eslint-disable-next-line no-redeclare
@@ -383,7 +375,7 @@ export function createActionListenerMiddleware<
383375
O extends ActionListenerOptions
384376
>(
385377
matcher: M,
386-
listener: ActionListener<GuardedType<M>, S, D, O>,
378+
listener: ActionListener<GuardedType<M>, S, D>,
387379
options?: O
388380
): Unsubscribe
389381
// eslint-disable-next-line no-redeclare
@@ -393,7 +385,7 @@ export function createActionListenerMiddleware<
393385
O extends ActionListenerOptions
394386
>(
395387
matcher: M,
396-
listener: ActionListener<AnyAction, S, D, O>,
388+
listener: ActionListener<AnyAction, S, D>,
397389
options?: O
398390
): Unsubscribe
399391
// eslint-disable-next-line no-redeclare
@@ -402,7 +394,7 @@ export function createActionListenerMiddleware<
402394
| string
403395
| TypedActionCreator<any>
404396
| ListenerPredicate<any, any>,
405-
listener: ActionListener<AnyAction, S, D, any>,
397+
listener: ActionListener<AnyAction, S, D>,
406398
options?: ActionListenerOptions
407399
): Unsubscribe {
408400
let predicate: ListenerPredicate<any, any>
@@ -448,17 +440,17 @@ export function createActionListenerMiddleware<
448440

449441
function removeListener<C extends TypedActionCreator<any>>(
450442
actionCreator: C,
451-
listener: ActionListener<ReturnType<C>, S, D, any>
443+
listener: ActionListener<ReturnType<C>, S, D>
452444
): boolean
453445
// eslint-disable-next-line no-redeclare
454446
function removeListener(
455447
type: string,
456-
listener: ActionListener<AnyAction, S, D, any>
448+
listener: ActionListener<AnyAction, S, D>
457449
): boolean
458450
// eslint-disable-next-line no-redeclare
459451
function removeListener(
460452
typeOrActionCreator: string | TypedActionCreator<any>,
461-
listener: ActionListener<AnyAction, S, D, any>
453+
listener: ActionListener<AnyAction, S, D>
462454
): boolean {
463455
const type =
464456
typeof typeOrActionCreator === 'string'

0 commit comments

Comments
 (0)