From e546d623b94be874ca1d925411afd654ba06586f Mon Sep 17 00:00:00 2001 From: Sigurd Fosseng Date: Sun, 13 Jan 2019 21:04:20 +0100 Subject: [PATCH] Allow action to be typed with any (#219) * Allow action to be typed with any * Adding more tests --- index.d.ts | 2 +- test/typescript.ts | 16 +++++++++++++++- 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/index.d.ts b/index.d.ts index 9992ad1..87fbcd6 100644 --- a/index.d.ts +++ b/index.d.ts @@ -1,8 +1,8 @@ import { Middleware, Action, AnyAction } from "redux"; export interface ThunkDispatch { - (action: T): T; (thunkAction: ThunkAction): R; + (action: T): T; } export type ThunkAction = ( diff --git a/test/typescript.ts b/test/typescript.ts index b263f50..162877b 100644 --- a/test/typescript.ts +++ b/test/typescript.ts @@ -1,5 +1,5 @@ import { createStore, applyMiddleware } from 'redux'; -import thunk, { ThunkAction, ThunkMiddleware } from '../index'; +import thunk, { ThunkAction, ThunkMiddleware, ThunkDispatch } from '../index'; type State = { foo: string; @@ -73,3 +73,17 @@ storeThunkArg.dispatch((dispatch, getState, extraArg) => { store.dispatch({ type: 'BAZ'}); console.log(extraArg); }); + +const callDispatchAsync_anyAction = (dispatch: ThunkDispatch) => { + const asyncThunk = (): ThunkResult> => () => ({} as Promise); + dispatch(asyncThunk()).then(() => console.log('done')) +} +const callDispatchAsync_specificActions = (dispatch: ThunkDispatch) => { + const asyncThunk = (): ThunkResult> => () => ({} as Promise); + dispatch(asyncThunk()).then(() => console.log('done')) +} +const callDispatchAny = (dispatch: ThunkDispatch) => { + const asyncThunk = (): any => () => ({} as Promise); + dispatch(asyncThunk()) // result is any + .then(() => console.log('done')) +} \ No newline at end of file