Skip to content

Commit

Permalink
more type fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
ben.durrant committed Apr 11, 2023
1 parent 3f9631a commit 0693e5e
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 19 deletions.
13 changes: 6 additions & 7 deletions test/applyMiddleware.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,10 @@ describe('applyMiddleware', () => {
})

it('wraps dispatch method with middleware once', () => {
function test(spyOnMethods: any) {
return (methods: any) => {
function test(spyOnMethods: any): Middleware {
return methods => {
spyOnMethods(methods)
return (next: Dispatch) => (action: Action) => next(action)
return next => action => next(action)
}
}

Expand All @@ -53,8 +53,8 @@ describe('applyMiddleware', () => {
})

it('passes recursive dispatches through the middleware chain', () => {
function test(spyOnMethods: any) {
return () => (next: Dispatch) => (action: Action) => {
function test(spyOnMethods: any): Middleware {
return () => next => action => {
spyOnMethods(action)
return next(action)
}
Expand Down Expand Up @@ -146,8 +146,7 @@ describe('applyMiddleware', () => {
}

function dummyMiddleware({ dispatch }: MiddlewareAPI) {
return (_next: Dispatch) => (action: Action) =>
dispatch(action, testCallArgs)
return (_next: unknown) => (action: any) => dispatch(action, testCallArgs)
}

const store = createStore(
Expand Down
20 changes: 8 additions & 12 deletions test/helpers/middleware.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,9 @@
import { MiddlewareAPI, Dispatch, AnyAction } from 'redux'
import { Dispatch, Middleware } from 'redux'

type ThunkAction<T extends any = any> = T extends AnyAction
? AnyAction
: T extends Function
? T
: never

export function thunk({ dispatch, getState }: MiddlewareAPI) {
return (next: Dispatch) =>
<_>(action: ThunkAction) =>
typeof action === 'function' ? action(dispatch, getState) : next(action)
}
export const thunk: Middleware<{
<R>(thunk: (dispatch: Dispatch, getState: () => any) => R): R
}> =
({ dispatch, getState }) =>
next =>
action =>
typeof action === 'function' ? action(dispatch, getState) : next(action)

0 comments on commit 0693e5e

Please sign in to comment.