66 StoreEnhancer ,
77 Dispatch ,
88 Observer ,
9- ExtendState ,
109 ListenerCallback
1110} from './types/store'
1211import { Action } from './types/actions'
@@ -43,7 +42,7 @@ import { kindOf } from './utils/kindOf'
4342export function createStore < S , A extends Action , Ext = { } , StateExt = never > (
4443 reducer : Reducer < S , A > ,
4544 enhancer ?: StoreEnhancer < Ext , StateExt >
46- ) : Store < ExtendState < S , StateExt > , A , StateExt , Ext > & Ext
45+ ) : Store < S , A , StateExt > & Ext
4746/**
4847 * @deprecated
4948 *
@@ -73,12 +72,12 @@ export function createStore<S, A extends Action, Ext = {}, StateExt = never>(
7372 reducer : Reducer < S , A > ,
7473 preloadedState ?: PreloadedState < S > ,
7574 enhancer ?: StoreEnhancer < Ext , StateExt >
76- ) : Store < ExtendState < S , StateExt > , A , StateExt , Ext > & Ext
75+ ) : Store < S , A , StateExt > & Ext
7776export function createStore < S , A extends Action , Ext = { } , StateExt = never > (
7877 reducer : Reducer < S , A > ,
7978 preloadedState ?: PreloadedState < S > | StoreEnhancer < Ext , StateExt > ,
8079 enhancer ?: StoreEnhancer < Ext , StateExt >
81- ) : Store < ExtendState < S , StateExt > , A , StateExt , Ext > & Ext {
80+ ) : Store < S , A , StateExt > & Ext {
8281 if ( typeof reducer !== 'function' ) {
8382 throw new Error (
8483 `Expected the root reducer to be a function. Instead, received: '${ kindOf (
@@ -115,7 +114,7 @@ export function createStore<S, A extends Action, Ext = {}, StateExt = never>(
115114 return enhancer ( createStore ) (
116115 reducer ,
117116 preloadedState as PreloadedState < S >
118- ) as Store < ExtendState < S , StateExt > , A , StateExt , Ext > & Ext
117+ ) as Store < S , A , StateExt > & Ext
119118 }
120119
121120 let currentReducer = reducer
@@ -291,11 +290,8 @@ export function createStore<S, A extends Action, Ext = {}, StateExt = never>(
291290 * implement a hot reloading mechanism for Redux.
292291 *
293292 * @param nextReducer The reducer for the store to use instead.
294- * @returns The same store instance with a new reducer in place.
295293 */
296- function replaceReducer < NewState , NewActions extends A > (
297- nextReducer : Reducer < NewState , NewActions >
298- ) : Store < ExtendState < NewState , StateExt > , NewActions , StateExt , Ext > & Ext {
294+ function replaceReducer ( nextReducer : Reducer < S , A > ) : void {
299295 if ( typeof nextReducer !== 'function' ) {
300296 throw new Error (
301297 `Expected the nextReducer to be a function. Instead, received: '${ kindOf (
@@ -304,22 +300,13 @@ export function createStore<S, A extends Action, Ext = {}, StateExt = never>(
304300 )
305301 }
306302
307- // TODO: do this more elegantly
308- ; ( currentReducer as unknown as Reducer < NewState , NewActions > ) = nextReducer
303+ currentReducer = nextReducer
309304
310305 // This action has a similar effect to ActionTypes.INIT.
311306 // Any reducers that existed in both the new and old rootReducer
312307 // will receive the previous state. This effectively populates
313308 // the new state tree with any relevant data from the old one.
314309 dispatch ( { type : ActionTypes . REPLACE } as A )
315- // change the type of the store by casting it to the new store
316- return store as unknown as Store <
317- ExtendState < NewState , StateExt > ,
318- NewActions ,
319- StateExt ,
320- Ext
321- > &
322- Ext
323310 }
324311
325312 /**
@@ -377,7 +364,7 @@ export function createStore<S, A extends Action, Ext = {}, StateExt = never>(
377364 getState,
378365 replaceReducer,
379366 [ $$observable ] : observable
380- } as unknown as Store < ExtendState < S , StateExt > , A , StateExt , Ext > & Ext
367+ } as unknown as Store < S , A , StateExt > & Ext
381368 return store
382369}
383370
@@ -419,7 +406,7 @@ export function legacy_createStore<
419406> (
420407 reducer : Reducer < S , A > ,
421408 enhancer ?: StoreEnhancer < Ext , StateExt >
422- ) : Store < ExtendState < S , StateExt > , A , StateExt , Ext > & Ext
409+ ) : Store < S , A , StateExt > & Ext
423410/**
424411 * Creates a Redux store that holds the state tree.
425412 *
@@ -459,7 +446,7 @@ export function legacy_createStore<
459446 reducer : Reducer < S , A > ,
460447 preloadedState ?: PreloadedState < S > ,
461448 enhancer ?: StoreEnhancer < Ext , StateExt >
462- ) : Store < ExtendState < S , StateExt > , A , StateExt , Ext > & Ext
449+ ) : Store < S , A , StateExt > & Ext
463450export function legacy_createStore <
464451 S ,
465452 A extends Action ,
@@ -469,6 +456,6 @@ export function legacy_createStore<
469456 reducer : Reducer < S , A > ,
470457 preloadedState ?: PreloadedState < S > | StoreEnhancer < Ext , StateExt > ,
471458 enhancer ?: StoreEnhancer < Ext , StateExt >
472- ) : Store < ExtendState < S , StateExt > , A , StateExt , Ext > & Ext {
459+ ) : Store < S , A , StateExt > & Ext {
473460 return createStore ( reducer , preloadedState as any , enhancer )
474461}
0 commit comments