Skip to content

Commit 6ffd8db

Browse files
committed
Fix ThunkActionDispatch: generic should expect to extend a function, not just the return type
1 parent d40faba commit 6ffd8db

File tree

2 files changed

+11
-2
lines changed

2 files changed

+11
-2
lines changed

index.d.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ export type ThunkAction<R, S, E, A extends Action> = (
2323
*
2424
* @template T ThunkAction to be wrapped
2525
*/
26-
export type ThunkActionDispatch<T extends ThunkAction<any, any, any, any>> = (...args: Parameters<T>)
26+
export type ThunkActionDispatch<T extends (...args: any[]) => ThunkAction<any, any, any, any>> = (...args: Parameters<T>)
2727
=> ReturnType<ReturnType<T>>;
2828

2929
export type ThunkMiddleware<S = {}, A extends Action = AnyAction, E = undefined> = Middleware<ThunkDispatch<S, E, A>, S, ThunkDispatch<S, E, A>>;

test/typescript.ts

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import {
66

77
import thunk, {
88
ThunkAction,
9+
ThunkActionDispatch,
910
ThunkDispatch,
1011
ThunkMiddleware,
1112
} from '../index';
@@ -68,14 +69,22 @@ function promiseThunkAction(): ThunkResult<Promise<boolean>> {
6869

6970
const standardAction = () => ({ type: 'FOO' });
7071

72+
interface ActionDispatchs {
73+
anotherThunkAction: ThunkActionDispatch<typeof anotherThunkAction>;
74+
promiseThunkAction: ThunkActionDispatch<typeof promiseThunkAction>;
75+
standardAction: typeof standardAction;
76+
}
77+
7178
// test that bindActionCreators correctly returns actions responses of ThunkActions
7279
// also ensure standard action creators still work as expected
73-
const actions = bindActionCreators({
80+
const actions: ActionDispatchs = bindActionCreators({
7481
anotherThunkAction,
7582
promiseThunkAction,
7683
standardAction,
7784
}, store.dispatch);
7885

86+
87+
7988
actions.anotherThunkAction() === 'hello';
8089
// typings:expect-error
8190
actions.anotherThunkAction() === false;

0 commit comments

Comments
 (0)