@@ -211,7 +211,7 @@ export function combineReducers<M extends ReducersMapObject<any, any>>(
211211 * dispatched.
212212 */
213213export interface Dispatch < A extends Action = AnyAction > {
214- < T extends A > ( action : T ) : T
214+ < T extends A > ( action : T , ... extraArgs : any [ ] ) : T
215215}
216216
217217/**
@@ -247,15 +247,33 @@ export type Observer<T> = {
247247 next ?( value : T ) : void
248248}
249249
250+ /**
251+ * Extend the state
252+ *
253+ * This is used by store enhancers and store creators to extend state.
254+ * If there is no state extension, it just returns the state, as is, otherwise
255+ * it returns the state joined with its extension.
256+ */
257+ export type ExtendState < State , Extension > = [ Extension ] extends [ never ]
258+ ? State
259+ : State & Extension
260+
250261/**
251262 * A store is an object that holds the application's state tree.
252263 * There should only be a single store in a Redux app, as the composition
253264 * happens on the reducer level.
254265 *
255266 * @template S The type of state held by this store.
256267 * @template A the type of actions which may be dispatched by this store.
268+ * @template StateExt any extension to state from store enhancers
269+ * @template Ext any extensions to the store from store enhancers
257270 */
258- export interface Store < S = any , A extends Action = AnyAction > {
271+ export interface Store <
272+ S = any ,
273+ A extends Action = AnyAction ,
274+ StateExt = never ,
275+ Ext = { }
276+ > {
259277 /**
260278 * Dispatches an action. It is the only way to trigger a state change.
261279 *
@@ -326,7 +344,9 @@ export interface Store<S = any, A extends Action = AnyAction> {
326344 *
327345 * @param nextReducer The reducer for the store to use instead.
328346 */
329- replaceReducer ( nextReducer : Reducer < S , A > ) : void
347+ replaceReducer < NewState , NewActions extends Action > (
348+ nextReducer : Reducer < NewState , NewActions >
349+ ) : Store < ExtendState < NewState , StateExt > , NewActions , StateExt , Ext > & Ext
330350
331351 /**
332352 * Interoperability point for observable/reactive libraries.
@@ -353,15 +373,15 @@ export type DeepPartial<T> = {
353373 * @template StateExt State extension that is mixed into the state type.
354374 */
355375export interface StoreCreator {
356- < S , A extends Action , Ext , StateExt > (
376+ < S , A extends Action , Ext = { } , StateExt = never > (
357377 reducer : Reducer < S , A > ,
358378 enhancer ?: StoreEnhancer < Ext , StateExt >
359- ) : Store < S & StateExt , A > & Ext
360- < S , A extends Action , Ext , StateExt > (
379+ ) : Store < ExtendState < S , StateExt > , A , StateExt , Ext > & Ext
380+ < S , A extends Action , Ext = { } , StateExt = never > (
361381 reducer : Reducer < S , A > ,
362382 preloadedState ?: PreloadedState < S > ,
363383 enhancer ?: StoreEnhancer < Ext >
364- ) : Store < S & StateExt , A > & Ext
384+ ) : Store < ExtendState < S , StateExt > , A , StateExt , Ext > & Ext
365385}
366386
367387/**
@@ -415,16 +435,17 @@ export const createStore: StoreCreator
415435 * @template Ext Store extension that is mixed into the Store type.
416436 * @template StateExt State extension that is mixed into the state type.
417437 */
418- export type StoreEnhancer < Ext = { } , StateExt = { } > = (
419- next : StoreEnhancerStoreCreator
438+ export type StoreEnhancer < Ext = { } , StateExt = never > = (
439+ next : StoreEnhancerStoreCreator < Ext , StateExt >
420440) => StoreEnhancerStoreCreator < Ext , StateExt >
421- export type StoreEnhancerStoreCreator < Ext = { } , StateExt = { } > = <
441+
442+ export type StoreEnhancerStoreCreator < Ext = { } , StateExt = never > = <
422443 S = any ,
423444 A extends Action = AnyAction
424445> (
425446 reducer : Reducer < S , A > ,
426447 preloadedState ?: PreloadedState < S >
427- ) => Store < S & StateExt , A > & Ext
448+ ) => Store < ExtendState < S , StateExt > , A , StateExt , Ext > & Ext
428449
429450/* middleware */
430451
@@ -667,3 +688,9 @@ export function compose<R>(
667688) : ( ...args : any [ ] ) => R
668689
669690export function compose < R > ( ...funcs : Function [ ] ) : ( ...args : any [ ] ) => R
691+
692+ export const __DO_NOT_USE__ActionTypes : {
693+ INIT : string
694+ REPLACE : string
695+ PROBE_UNKNOWN_ACTION : ( ) => string
696+ }
0 commit comments