Skip to content

Commit e767e13

Browse files
committed
Improve basic dispatch signature. Fix typescript tests.
1 parent 2d29481 commit e767e13

File tree

3 files changed

+6
-5
lines changed

3 files changed

+6
-5
lines changed

index.d.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ export function combineReducers<S>(reducers: ReducersMapObject): Reducer<S>;
9494
* before passing them to the next middleware.
9595
*/
9696
export interface Dispatch<S> {
97-
(action: Action): Action;
97+
<A extends Action>(action: A): A;
9898
}
9999

100100
/**
@@ -267,7 +267,7 @@ export interface MiddlewareAPI<S> {
267267
* asynchronous API call into a series of synchronous actions.
268268
*/
269269
export interface Middleware {
270-
<S>(api: MiddlewareAPI<S>): (next: Dispatch<S>) => any;
270+
<S>(api: MiddlewareAPI<S>): (next: Dispatch<S>) => Dispatch<S>;
271271
}
272272

273273
/**

test/typescript/actionCreators.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,15 +15,15 @@ const addTodo: ActionCreator<AddTodoAction> = (text: string) => ({
1515

1616
const addTodoAction: AddTodoAction = addTodo('test');
1717

18-
type AddTodoThunk = (dispatch: Dispatch) => AddTodoAction;
18+
type AddTodoThunk = (dispatch: Dispatch<any>) => AddTodoAction;
1919

2020
const addTodoViaThunk: ActionCreator<AddTodoThunk> = (text: string) =>
21-
(dispatch: Dispatch) => ({
21+
(dispatch: Dispatch<any>) => ({
2222
type: 'ADD_TODO',
2323
text
2424
})
2525

26-
declare const dispatch: Dispatch;
26+
declare const dispatch: Dispatch<any>;
2727

2828
const boundAddTodo = bindActionCreators(addTodo, dispatch);
2929

test/typescript/dispatch.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,3 +13,4 @@ declare module "../../index.d.ts" {
1313
}
1414

1515
const dispatchThunkResult: number = dispatch(() => 42);
16+
const dispatchedTimerId: number = dispatch(d => setTimeout(() => d({type: 'TYPE'}), 1000));

0 commit comments

Comments
 (0)