Skip to content

Commit 0693e5e

Browse files
author
ben.durrant
committed
more type fixes
1 parent 3f9631a commit 0693e5e

File tree

2 files changed

+14
-19
lines changed

2 files changed

+14
-19
lines changed

test/applyMiddleware.spec.ts

+6-7
Original file line numberDiff line numberDiff line change
@@ -28,10 +28,10 @@ describe('applyMiddleware', () => {
2828
})
2929

3030
it('wraps dispatch method with middleware once', () => {
31-
function test(spyOnMethods: any) {
32-
return (methods: any) => {
31+
function test(spyOnMethods: any): Middleware {
32+
return methods => {
3333
spyOnMethods(methods)
34-
return (next: Dispatch) => (action: Action) => next(action)
34+
return next => action => next(action)
3535
}
3636
}
3737

@@ -53,8 +53,8 @@ describe('applyMiddleware', () => {
5353
})
5454

5555
it('passes recursive dispatches through the middleware chain', () => {
56-
function test(spyOnMethods: any) {
57-
return () => (next: Dispatch) => (action: Action) => {
56+
function test(spyOnMethods: any): Middleware {
57+
return () => next => action => {
5858
spyOnMethods(action)
5959
return next(action)
6060
}
@@ -146,8 +146,7 @@ describe('applyMiddleware', () => {
146146
}
147147

148148
function dummyMiddleware({ dispatch }: MiddlewareAPI) {
149-
return (_next: Dispatch) => (action: Action) =>
150-
dispatch(action, testCallArgs)
149+
return (_next: unknown) => (action: any) => dispatch(action, testCallArgs)
151150
}
152151

153152
const store = createStore(

test/helpers/middleware.ts

+8-12
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,9 @@
1-
import { MiddlewareAPI, Dispatch, AnyAction } from 'redux'
1+
import { Dispatch, Middleware } from 'redux'
22

3-
type ThunkAction<T extends any = any> = T extends AnyAction
4-
? AnyAction
5-
: T extends Function
6-
? T
7-
: never
8-
9-
export function thunk({ dispatch, getState }: MiddlewareAPI) {
10-
return (next: Dispatch) =>
11-
<_>(action: ThunkAction) =>
12-
typeof action === 'function' ? action(dispatch, getState) : next(action)
13-
}
3+
export const thunk: Middleware<{
4+
<R>(thunk: (dispatch: Dispatch, getState: () => any) => R): R
5+
}> =
6+
({ dispatch, getState }) =>
7+
next =>
8+
action =>
9+
typeof action === 'function' ? action(dispatch, getState) : next(action)

0 commit comments

Comments
 (0)