From deb9ad1bd5360ed36e6b8524151911030f3a200c Mon Sep 17 00:00:00 2001 From: Tom Crockett Date: Mon, 23 Oct 2017 00:12:43 +0000 Subject: [PATCH] Fix TS definitions test for new Dispatch typing (#2674) * Fix TypeScript definitions test for new Dispatch typing * Be explicit about type parameters --- test/typescript/dispatch.ts | 4 ++-- test/typescript/middleware.ts | 16 ++++++++-------- 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/test/typescript/dispatch.ts b/test/typescript/dispatch.ts index 6f051421f2..c5361dee36 100644 --- a/test/typescript/dispatch.ts +++ b/test/typescript/dispatch.ts @@ -7,8 +7,8 @@ const dispatchResult: Action = dispatch({type: 'TYPE'}); // thunk declare module "../../" { - export interface Dispatch { - (asyncAction: (dispatch: Dispatch, getState: () => S) => R): R; + export interface Dispatch { + (asyncAction: (dispatch: Dispatch, getState: () => any) => R): R; } } diff --git a/test/typescript/middleware.ts b/test/typescript/middleware.ts index b3aaf9ae9b..f25fa2db30 100644 --- a/test/typescript/middleware.ts +++ b/test/typescript/middleware.ts @@ -4,17 +4,17 @@ import { } from "../../" declare module "../../" { - export interface Dispatch { - (asyncAction: (dispatch: Dispatch, getState: () => S) => R): R; + export interface Dispatch { + (asyncAction: (dispatch: Dispatch, getState: () => any) => R): R; } } -type Thunk = (dispatch: Dispatch, getState?: () => S) => O; +type Thunk = (dispatch: Dispatch, getState?: () => S) => O; const thunkMiddleware: Middleware = - ({dispatch, getState}: MiddlewareAPI) => - (next: Dispatch) => - (action: A | Thunk): B|Action => + ({dispatch, getState}: MiddlewareAPI) => + (next: Dispatch) => + (action: A | Thunk): B|Action => typeof action === 'function' ? (>action)(dispatch, getState) : next(action) @@ -22,7 +22,7 @@ const thunkMiddleware: Middleware = const loggerMiddleware: Middleware = ({getState}: MiddlewareAPI) => - (next: Dispatch) => + (next: Dispatch) => (action: any): any => { console.log('will dispatch', action) @@ -51,7 +51,7 @@ const storeWithThunkMiddleware = createStore( ); storeWithThunkMiddleware.dispatch( - (dispatch: Dispatch, getState: () => State) => { + (dispatch: Dispatch, getState: () => State) => { const todos: string[] = getState().todos; dispatch({type: 'ADD_TODO'}) }