Skip to content

Commit a2200d5

Browse files
pelotomtimdorr
authored andcommitted
Fix TS definitions test for new Dispatch typing (#2674)
* Fix TypeScript definitions test for new Dispatch typing * Be explicit about type parameters
1 parent 80a5ac5 commit a2200d5

File tree

2 files changed

+10
-10
lines changed

2 files changed

+10
-10
lines changed

test/typescript/dispatch.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@ const dispatchResult: Action = dispatch({type: 'TYPE'});
77

88
// thunk
99
declare module "../../" {
10-
export interface Dispatch<S> {
11-
<R>(asyncAction: (dispatch: Dispatch<S>, getState: () => S) => R): R;
10+
export interface Dispatch<D = Action> {
11+
<R>(asyncAction: (dispatch: Dispatch<D>, getState: () => any) => R): R;
1212
}
1313
}
1414

test/typescript/middleware.ts

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,25 +4,25 @@ import {
44
} from "../../"
55

66
declare module "../../" {
7-
export interface Dispatch<S> {
8-
<R>(asyncAction: (dispatch: Dispatch<S>, getState: () => S) => R): R;
7+
export interface Dispatch<D = Action> {
8+
<R>(asyncAction: (dispatch: Dispatch<D>, getState: () => any) => R): R;
99
}
1010
}
1111

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

1414
const thunkMiddleware: Middleware =
15-
<S>({dispatch, getState}: MiddlewareAPI<S>) =>
16-
(next: Dispatch<S>) =>
17-
<A extends Action, B>(action: A | Thunk<S, B>): B|Action =>
15+
<S, A extends Action>({dispatch, getState}: MiddlewareAPI<S>) =>
16+
(next: Dispatch<A>) =>
17+
<B>(action: A | Thunk<S, B>): B|Action =>
1818
typeof action === 'function' ?
1919
(<Thunk<S, B>>action)(dispatch, getState) :
2020
next(<A>action)
2121

2222

2323
const loggerMiddleware: Middleware =
2424
<S>({getState}: MiddlewareAPI<S>) =>
25-
(next: Dispatch<S>) =>
25+
(next: Dispatch) =>
2626
(action: any): any => {
2727
console.log('will dispatch', action)
2828

@@ -51,7 +51,7 @@ const storeWithThunkMiddleware = createStore(
5151
);
5252

5353
storeWithThunkMiddleware.dispatch(
54-
(dispatch: Dispatch<State>, getState: () => State) => {
54+
(dispatch: Dispatch, getState: () => State) => {
5555
const todos: string[] = getState().todos;
5656
dispatch({type: 'ADD_TODO'})
5757
}

0 commit comments

Comments
 (0)