Skip to content

Commit 1c06e2c

Browse files
committed
Updated the definition of 'Reducer' and 'Dispatch' for TypeScript 2.3+
1 parent 4acb40c commit 1c06e2c

File tree

1 file changed

+11
-11
lines changed

1 file changed

+11
-11
lines changed

index.d.ts

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ export interface Action {
4343
*
4444
* @template S State object type.
4545
*/
46-
export type Reducer<S> = <A extends Action>(state: S | undefined, action: A) => S;
46+
export type Reducer<S, A extends Action = Action> = (state: S | undefined, action: A) => S;
4747

4848
/**
4949
* Object whose values correspond to different reducer functions.
@@ -93,8 +93,8 @@ export function combineReducers<S>(reducers: ReducersMapObject<S>): Reducer<S>;
9393
* transform, delay, ignore, or otherwise interpret actions or async actions
9494
* before passing them to the next middleware.
9595
*/
96-
export interface Dispatch<S> {
97-
<A extends Action>(action: A): A;
96+
export interface Dispatch<TInput = Action, TReturn = Action> {
97+
(input: TInput): TReturn;
9898
}
9999

100100
/**
@@ -138,7 +138,7 @@ export interface Store<S> {
138138
* Note that, if you use a custom middleware, it may wrap `dispatch()` to
139139
* return something else (for example, a Promise you can await).
140140
*/
141-
dispatch: Dispatch<S>;
141+
dispatch: Dispatch;
142142

143143
/**
144144
* Reads the state tree managed by the store.
@@ -254,7 +254,7 @@ export const createStore: StoreCreator;
254254
/* middleware */
255255

256256
export interface MiddlewareAPI<S> {
257-
dispatch: Dispatch<S>;
257+
dispatch: Dispatch;
258258
getState(): S;
259259
}
260260

@@ -267,8 +267,8 @@ export interface MiddlewareAPI<S> {
267267
* logging actions, performing side effects like routing, or turning an
268268
* asynchronous API call into a series of synchronous actions.
269269
*/
270-
export interface Middleware {
271-
<S>(api: MiddlewareAPI<S>): (next: Dispatch<S>) => Dispatch<S>;
270+
export interface Middleware<S> {
271+
(api: MiddlewareAPI<S>): (next: Dispatch) => Dispatch;
272272
}
273273

274274
/**
@@ -340,19 +340,19 @@ export interface ActionCreatorsMapObject {
340340
* creator wrapped into the `dispatch` call. If you passed a function as
341341
* `actionCreator`, the return value will also be a single function.
342342
*/
343-
export function bindActionCreators<A extends ActionCreator<any>>(actionCreator: A, dispatch: Dispatch<any>): A;
343+
export function bindActionCreators<A extends ActionCreator<any>>(actionCreator: A, dispatch: Dispatch): A;
344344

345345
export function bindActionCreators<
346346
A extends ActionCreator<any>,
347347
B extends ActionCreator<any>
348-
>(actionCreator: A, dispatch: Dispatch<any>): B;
348+
>(actionCreator: A, dispatch: Dispatch): B;
349349

350-
export function bindActionCreators<M extends ActionCreatorsMapObject>(actionCreators: M, dispatch: Dispatch<any>): M;
350+
export function bindActionCreators<M extends ActionCreatorsMapObject>(actionCreators: M, dispatch: Dispatch): M;
351351

352352
export function bindActionCreators<
353353
M extends ActionCreatorsMapObject,
354354
N extends ActionCreatorsMapObject
355-
>(actionCreators: M, dispatch: Dispatch<any>): N;
355+
>(actionCreators: M, dispatch: Dispatch): N;
356356

357357

358358
/* compose */

0 commit comments

Comments
 (0)