Skip to content

Commit 658fa6f

Browse files
committed
Fix typescript tests of middlewares.
1 parent e767e13 commit 658fa6f

File tree

1 file changed

+11
-6
lines changed

1 file changed

+11
-6
lines changed

test/typescript/middleware.ts

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,21 +3,26 @@ import {
33
applyMiddleware, createStore, Dispatch, Reducer, Action
44
} from "../../index.d.ts";
55

6+
declare module "../../index.d.ts" {
7+
export interface Dispatch<S> {
8+
<R>(asyncAction: (dispatch: Dispatch<S>, getState: () => S) => R): R;
9+
}
10+
}
611

7-
type Thunk<S, O> = (dispatch: Dispatch, getState?: () => S) => O;
12+
type Thunk<S, O> = (dispatch: Dispatch<S>, getState: () => S) => O;
813

914
const thunkMiddleware: Middleware =
1015
<S>({dispatch, getState}: MiddlewareAPI<S>) =>
11-
(next: Dispatch) =>
12-
<A, B>(action: A | Thunk<S, B>): B =>
16+
(next: Dispatch<S>) =>
17+
<A extends Action, B>(action: A | Thunk<S, B>): B|Action =>
1318
typeof action === 'function' ?
1419
(<Thunk<S, B>>action)(dispatch, getState) :
15-
<B>next(<A>action)
20+
next(<A>action)
1621

1722

1823
const loggerMiddleware: Middleware =
1924
<S>({getState}: MiddlewareAPI<S>) =>
20-
(next: Dispatch) =>
25+
(next: Dispatch<S>) =>
2126
(action: any): any => {
2227
console.log('will dispatch', action)
2328

@@ -47,7 +52,7 @@ const storeWithThunkMiddleware = createStore(
4752
);
4853

4954
storeWithThunkMiddleware.dispatch(
50-
(dispatch: Dispatch, getState: () => State) => {
55+
(dispatch, getState) => {
5156
const todos: string[] = getState().todos;
5257
dispatch({type: 'ADD_TODO'})
5358
}

0 commit comments

Comments
 (0)