forked from piotrwitek/react-redux-typescript-guide
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.d.ts
58 lines (51 loc) · 1.53 KB
/
index.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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
import {
Action,
ActionCreatorsMapObject,
AnyAction,
Dispatch,
Middleware,
} from 'redux';
export interface ThunkDispatch<S, E, A extends Action> {
<R>(thunkAction: ThunkAction<R, S, E, A>): R;
<T extends A>(action: T): T;
}
export type ThunkAction<R, S, E, A extends Action> = (
dispatch: ThunkDispatch<S, E, A>,
getState: () => S,
extraArgument: E
) => R;
/**
* Takes a ThunkAction and returns a function signature which matches how it would appear when processed using
* bindActionCreators
*
* @template T ThunkAction to be wrapped
*/
export type ThunkActionDispatch<
T extends (...args: any[]) => ThunkAction<any, any, any, any>
> = (...args: Parameters<T>) => ReturnType<ReturnType<T>>;
export type ThunkMiddleware<
S = {},
A extends Action = AnyAction,
E = undefined
> = Middleware<ThunkDispatch<S, E, A>, S, ThunkDispatch<S, E, A>>;
declare const thunk: ThunkMiddleware & {
withExtraArgument<E>(extraArgument: E): ThunkMiddleware<{}, AnyAction, E>;
};
export default thunk;
/**
* Redux behaviour changed by middleware, so overloads here
*/
declare module 'redux' {
/**
* Overload for bindActionCreators redux function, returns expects responses
* from thunk actions
*/
function bindActionCreators<M extends ActionCreatorsMapObject<any>>(
actionCreators: M,
dispatch: Dispatch
): {
[N in keyof M]: ReturnType<M[N]> extends ThunkAction<any, any, any, any>
? (...args: Parameters<M[N]>) => ReturnType<ReturnType<M[N]>>
: M[N]
};
}