forked from reduxjs/redux-thunk
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathextend-redux.d.ts
42 lines (40 loc) · 1.43 KB
/
extend-redux.d.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
import { ThunkAction } from './src/index';
/**
* Globally alter the Redux `bindActionCreators` and `Dispatch` types to assume
* that the thunk middleware always exists, for ease of use.
* This is kept as a separate file that may be optionally imported, to
* avoid polluting the default types in case the thunk middleware is _not_
* actually being used.
*
* To add these types to your app:
* import 'redux-thunk/extend-redux'
*/
declare module 'redux' {
/**
* Overload for bindActionCreators redux function, returns expects responses
* from thunk actions
*/
function bindActionCreators<
TActionCreators extends ActionCreatorsMapObject<any>
>(
actionCreators: TActionCreators,
dispatch: Dispatch,
): {
[TActionCreatorName in keyof TActionCreators]: ReturnType<
TActionCreators[TActionCreatorName]
> extends ThunkAction<any, any, any, any>
? (
...args: Parameters<TActionCreators[TActionCreatorName]>
) => ReturnType<ReturnType<TActionCreators[TActionCreatorName]>>
: 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<A extends Action = AnyAction> {
<TReturnType = any, TState = any, TExtraThunkArg = any>(
thunkAction: ThunkAction<TReturnType, TState, TExtraThunkArg, A>,
): TReturnType;
}
}