@@ -43,13 +43,13 @@ export interface Action {
43
43
*
44
44
* @template S State object type.
45
45
*/
46
- export type Reducer < S > = < A extends Action > ( state : S , action : A ) => S ;
46
+ export type Reducer < S > = < A extends Action > ( state : S | undefined , action : A ) => S ;
47
47
48
48
/**
49
49
* Object whose values correspond to different reducer functions.
50
50
*/
51
- export interface ReducersMapObject {
52
- [ key : string ] : Reducer < any > ;
51
+ export type ReducersMapObject < S > = {
52
+ [ K in keyof S ] : Reducer < S [ K ] > ;
53
53
}
54
54
55
55
/**
@@ -70,7 +70,7 @@ export interface ReducersMapObject {
70
70
* @returns A reducer function that invokes every reducer inside the passed
71
71
* object, and builds a state object with the same shape.
72
72
*/
73
- export function combineReducers < S > ( reducers : ReducersMapObject ) : Reducer < S > ;
73
+ export function combineReducers < S > ( reducers : ReducersMapObject < S > ) : Reducer < S > ;
74
74
75
75
76
76
/* store */
@@ -93,7 +93,9 @@ export function combineReducers<S>(reducers: ReducersMapObject): Reducer<S>;
93
93
* transform, delay, ignore, or otherwise interpret actions or async actions
94
94
* before passing them to the next middleware.
95
95
*/
96
- export type Dispatch = ( action : any ) => any ;
96
+ export interface Dispatch < S > {
97
+ < A extends Action > ( action : A ) : A ;
98
+ }
97
99
98
100
/**
99
101
* Function to remove listener added by `Store.subscribe()`.
@@ -136,7 +138,7 @@ export interface Store<S> {
136
138
* Note that, if you use a custom middleware, it may wrap `dispatch()` to
137
139
* return something else (for example, a Promise you can await).
138
140
*/
139
- dispatch : Dispatch ;
141
+ dispatch : Dispatch < S > ;
140
142
141
143
/**
142
144
* Reads the state tree managed by the store.
@@ -251,7 +253,7 @@ export const createStore: StoreCreator;
251
253
/* middleware */
252
254
253
255
export interface MiddlewareAPI < S > {
254
- dispatch : Dispatch ;
256
+ dispatch : Dispatch < S > ;
255
257
getState ( ) : S ;
256
258
}
257
259
@@ -265,7 +267,7 @@ export interface MiddlewareAPI<S> {
265
267
* asynchronous API call into a series of synchronous actions.
266
268
*/
267
269
export interface Middleware {
268
- < S > ( api : MiddlewareAPI < S > ) : ( next : Dispatch ) => ( action : any ) => any ;
270
+ < S > ( api : MiddlewareAPI < S > ) : ( next : Dispatch < S > ) => Dispatch < S > ;
269
271
}
270
272
271
273
/**
@@ -337,19 +339,19 @@ export interface ActionCreatorsMapObject {
337
339
* creator wrapped into the `dispatch` call. If you passed a function as
338
340
* `actionCreator`, the return value will also be a single function.
339
341
*/
340
- export function bindActionCreators < A extends ActionCreator < any > > ( actionCreator : A , dispatch : Dispatch ) : A ;
342
+ export function bindActionCreators < A extends ActionCreator < any > > ( actionCreator : A , dispatch : Dispatch < any > ) : A ;
341
343
342
344
export function bindActionCreators <
343
345
A extends ActionCreator < any > ,
344
346
B extends ActionCreator < any >
345
- > ( actionCreator : A , dispatch : Dispatch ) : B ;
347
+ > ( actionCreator : A , dispatch : Dispatch < any > ) : B ;
346
348
347
- export function bindActionCreators < M extends ActionCreatorsMapObject > ( actionCreators : M , dispatch : Dispatch ) : M ;
349
+ export function bindActionCreators < M extends ActionCreatorsMapObject > ( actionCreators : M , dispatch : Dispatch < any > ) : M ;
348
350
349
351
export function bindActionCreators <
350
352
M extends ActionCreatorsMapObject ,
351
353
N extends ActionCreatorsMapObject
352
- > ( actionCreators : M , dispatch : Dispatch ) : N ;
354
+ > ( actionCreators : M , dispatch : Dispatch < any > ) : N ;
353
355
354
356
355
357
/* compose */
0 commit comments