@@ -43,13 +43,13 @@ export interface Action {
4343 *
4444 * @template S State object type.
4545 */
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 ;
4747
4848/**
4949 * Object whose values correspond to different reducer functions.
5050 */
51- export interface ReducersMapObject {
52- [ key : string ] : Reducer < any > ;
51+ export type ReducersMapObject < S > = {
52+ [ K in keyof S ] : Reducer < S [ K ] > ;
5353}
5454
5555/**
@@ -70,7 +70,7 @@ export interface ReducersMapObject {
7070 * @returns A reducer function that invokes every reducer inside the passed
7171 * object, and builds a state object with the same shape.
7272 */
73- export function combineReducers < S > ( reducers : ReducersMapObject ) : Reducer < S > ;
73+ export function combineReducers < S > ( reducers : ReducersMapObject < S > ) : Reducer < S > ;
7474
7575
7676/* store */
@@ -93,7 +93,9 @@ export function combineReducers<S>(reducers: ReducersMapObject): Reducer<S>;
9393 * transform, delay, ignore, or otherwise interpret actions or async actions
9494 * before passing them to the next middleware.
9595 */
96- export type Dispatch = ( action : any ) => any ;
96+ export interface Dispatch < S > {
97+ < A extends Action > ( action : A ) : A ;
98+ }
9799
98100/**
99101 * Function to remove listener added by `Store.subscribe()`.
@@ -136,7 +138,7 @@ export interface Store<S> {
136138 * Note that, if you use a custom middleware, it may wrap `dispatch()` to
137139 * return something else (for example, a Promise you can await).
138140 */
139- dispatch : Dispatch ;
141+ dispatch : Dispatch < S > ;
140142
141143 /**
142144 * Reads the state tree managed by the store.
@@ -251,7 +253,7 @@ export const createStore: StoreCreator;
251253/* middleware */
252254
253255export interface MiddlewareAPI < S > {
254- dispatch : Dispatch ;
256+ dispatch : Dispatch < S > ;
255257 getState ( ) : S ;
256258}
257259
@@ -265,7 +267,7 @@ export interface MiddlewareAPI<S> {
265267 * asynchronous API call into a series of synchronous actions.
266268 */
267269export interface Middleware {
268- < S > ( api : MiddlewareAPI < S > ) : ( next : Dispatch ) => ( action : any ) => any ;
270+ < S > ( api : MiddlewareAPI < S > ) : ( next : Dispatch < S > ) => Dispatch < S > ;
269271}
270272
271273/**
@@ -337,19 +339,19 @@ export interface ActionCreatorsMapObject {
337339 * creator wrapped into the `dispatch` call. If you passed a function as
338340 * `actionCreator`, the return value will also be a single function.
339341 */
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 ;
341343
342344export function bindActionCreators <
343345 A extends ActionCreator < any > ,
344346 B extends ActionCreator < any >
345- > ( actionCreator : A , dispatch : Dispatch ) : B ;
347+ > ( actionCreator : A , dispatch : Dispatch < any > ) : B ;
346348
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 ;
348350
349351export function bindActionCreators <
350352 M extends ActionCreatorsMapObject ,
351353 N extends ActionCreatorsMapObject
352- > ( actionCreators : M , dispatch : Dispatch ) : N ;
354+ > ( actionCreators : M , dispatch : Dispatch < any > ) : N ;
353355
354356
355357/* compose */
0 commit comments