diff --git a/src/index.d.ts b/src/index.d.ts index 3267416..61f3e21 100644 --- a/src/index.d.ts +++ b/src/index.d.ts @@ -122,4 +122,14 @@ declare module 'redux' { ) => ReturnType> : TActionCreators[TActionCreatorName]; }; + + /* + * Overload to add thunk support to Redux's dispatch() function. + * Useful for react-redux or any other library which could use this type. + */ + export interface Dispatch { + ( + thunkAction: ThunkAction, + ): TReturnType; + } } diff --git a/test/typescript.ts b/test/typescript.ts index c6015b1..5ba46d8 100644 --- a/test/typescript.ts +++ b/test/typescript.ts @@ -1,4 +1,9 @@ -import { applyMiddleware, bindActionCreators, createStore } from 'redux'; +import { + applyMiddleware, + bindActionCreators, + createStore, + Dispatch, +} from 'redux'; import thunk, { ThunkAction, @@ -144,3 +149,8 @@ const callDispatchAny = ( dispatch(asyncThunk()) // result is any .then(() => console.log('done')); }; + +const untypedStore = createStore(fakeReducer, applyMiddleware(thunk)); + +untypedStore.dispatch(anotherThunkAction()); +untypedStore.dispatch(promiseThunkAction()).then(() => Promise.resolve());