Skip to content

Commit 3f9631a

Browse files
author
ben.durrant
committed
fix type tests - make next unknown function
1 parent 3b79b52 commit 3f9631a

File tree

2 files changed

+16
-20
lines changed

2 files changed

+16
-20
lines changed

src/types/middleware.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,6 @@ export interface Middleware<
2525
D extends Dispatch = Dispatch
2626
> {
2727
(api: MiddlewareAPI<D, S>): (
28-
next: D
29-
) => (action: unknown) => any
28+
next: (action: unknown) => unknown
29+
) => (action: unknown) => unknown
3030
}

test/typescript/middleware.ts

Lines changed: 14 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,8 @@ import {
1515
*/
1616
function logger() {
1717
const loggerMiddleware: Middleware =
18-
({ getState }: MiddlewareAPI) =>
19-
(next: Dispatch) =>
18+
({ getState }) =>
19+
next =>
2020
action => {
2121
console.log('will dispatch', action)
2222

@@ -41,9 +41,9 @@ type PromiseDispatch = <T extends Action>(promise: Promise<T>) => Promise<T>
4141

4242
function promise() {
4343
const promiseMiddleware: Middleware<PromiseDispatch> =
44-
({ dispatch }: MiddlewareAPI) =>
44+
({ dispatch }) =>
4545
next =>
46-
<T extends Action>(action: AnyAction | Promise<T>) => {
46+
action => {
4747
if (action instanceof Promise) {
4848
action.then(dispatch)
4949
return action
@@ -72,13 +72,10 @@ function thunk<S, DispatchExt>() {
7272
ThunkDispatch<S, DispatchExt>,
7373
S,
7474
Dispatch & ThunkDispatch<S>
75-
> =
76-
api =>
77-
(next: Dispatch) =>
78-
<R>(action: AnyAction | Thunk<R, any>) =>
79-
typeof action === 'function'
80-
? action(api.dispatch, api.getState)
81-
: next(action)
75+
> = api => next => action =>
76+
typeof action === 'function'
77+
? action(api.dispatch, api.getState)
78+
: next(action)
8279

8380
return thunkMiddleware
8481
}
@@ -89,14 +86,13 @@ function thunk<S, DispatchExt>() {
8986
function customState() {
9087
type State = { field: 'string' }
9188

92-
const customMiddleware: Middleware<{}, State> =
93-
api => (next: Dispatch) => action => {
94-
api.getState().field
95-
// @ts-expect-error
96-
api.getState().wrongField
89+
const customMiddleware: Middleware<{}, State> = api => next => action => {
90+
api.getState().field
91+
// @ts-expect-error
92+
api.getState().wrongField
9793

98-
return next(action)
99-
}
94+
return next(action)
95+
}
10096

10197
return customMiddleware
10298
}

0 commit comments

Comments
 (0)