Skip to content

Commit 2294698

Browse files
committed
Add exported ThunkAction type
1 parent b0ec79c commit 2294698

File tree

2 files changed

+18
-5
lines changed

2 files changed

+18
-5
lines changed

index.d.ts

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
1-
import {Middleware} from "redux";
1+
import {Middleware, Dispatch} from "redux";
22

33

4+
export type ThunkAction<R, S, E> = (dispatch: Dispatch<S>, getState: () => S,
5+
extraArgument: E) => R;
6+
47
declare module "redux" {
58
export interface Dispatch<S> {
6-
<R>(asyncAction: (dispatch: Dispatch<S>,
7-
getState?: () => S,
8-
extraArgument?: any) => R): R;
9+
<R, E>(asyncAction: ThunkAction<R, S, E>): R;
910
}
1011
}
1112

test/typescript.ts

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import {Store, Middleware} from 'redux';
2-
import thunk from '../index.d.ts';
2+
import thunk, {ThunkAction} from '../index.d.ts';
33

44

55
declare const store: Store<{foo: string}>;
@@ -19,3 +19,15 @@ const middleware: Middleware = thunk.withExtraArgument('bar');
1919
store.dispatch((dispatch, getState, extraArg) => {
2020
console.log(extraArg);
2121
});
22+
23+
const thunkAction: ThunkAction<void, {foo: string}, {bar: number}> =
24+
(dispatch, getState, extraArg) => {
25+
const foo: string = getState().foo;
26+
const bar: number = extraArg.bar;
27+
28+
dispatch({type: 'FOO'});
29+
};
30+
31+
const thunkActionDispatchOnly: ThunkAction<void, {}, {}> = dispatch => {
32+
dispatch({type: 'FOO'});
33+
};

0 commit comments

Comments
 (0)