UNPKG

1.48 kBTypeScriptView Raw
1import { ThunkAction } from './src/index'
2
3/**
4 * Globally alter the Redux `bindActionCreators` and `Dispatch` types to assume
5 * that the thunk middleware always exists, for ease of use.
6 * This is kept as a separate file that may be optionally imported, to
7 * avoid polluting the default types in case the thunk middleware is _not_
8 * actually being used.
9 *
10 * To add these types to your app:
11 * import 'redux-thunk/extend-redux'
12 */
13declare module 'redux' {
14 /**
15 * Overload for bindActionCreators redux function, returns expects responses
16 * from thunk actions
17 */
18 function bindActionCreators<
19 ActionCreators extends ActionCreatorsMapObject<any>
20 >(
21 actionCreators: ActionCreators,
22 dispatch: Dispatch
23 ): {
24 [ActionCreatorName in keyof ActionCreators]: ReturnType<
25 ActionCreators[ActionCreatorName]
26 > extends ThunkAction<any, any, any, any>
27 ? (
28 ...args: Parameters<ActionCreators[ActionCreatorName]>
29 ) => ReturnType<ReturnType<ActionCreators[ActionCreatorName]>>
30 : ActionCreators[ActionCreatorName]
31 }
32
33 /*
34 * Overload to add thunk support to Redux's dispatch() function.
35 * Useful for react-redux or any other library which could use this type.
36 */
37 export interface Dispatch<A extends Action = AnyAction> {
38 <ReturnType = any, State = any, ExtraThunkArg = any>(
39 thunkAction: ThunkAction<ReturnType, State, ExtraThunkArg, A>
40 ): ReturnType
41 }
42}