55 PreloadedState ,
66 StoreEnhancer ,
77 Dispatch ,
8- Observer ,
9- ExtendState
8+ Observer
109} from './types/store'
1110import { Action } from './types/actions'
1211import { Reducer } from './types/reducers'
@@ -42,7 +41,7 @@ import { kindOf } from './utils/kindOf'
4241export function createStore < S , A extends Action , Ext = { } , StateExt = never > (
4342 reducer : Reducer < S , A > ,
4443 enhancer ?: StoreEnhancer < Ext , StateExt >
45- ) : Store < ExtendState < S , StateExt > , A , StateExt , Ext > & Ext
44+ ) : Store < S , A , StateExt > & Ext
4645/**
4746 * @deprecated
4847 *
@@ -72,12 +71,12 @@ export function createStore<S, A extends Action, Ext = {}, StateExt = never>(
7271 reducer : Reducer < S , A > ,
7372 preloadedState ?: PreloadedState < S > ,
7473 enhancer ?: StoreEnhancer < Ext , StateExt >
75- ) : Store < ExtendState < S , StateExt > , A , StateExt , Ext > & Ext
74+ ) : Store < S , A , StateExt > & Ext
7675export function createStore < S , A extends Action , Ext = { } , StateExt = never > (
7776 reducer : Reducer < S , A > ,
7877 preloadedState ?: PreloadedState < S > | StoreEnhancer < Ext , StateExt > ,
7978 enhancer ?: StoreEnhancer < Ext , StateExt >
80- ) : Store < ExtendState < S , StateExt > , A , StateExt , Ext > & Ext {
79+ ) : Store < S , A , StateExt > & Ext {
8180 if ( typeof reducer !== 'function' ) {
8281 throw new Error (
8382 `Expected the root reducer to be a function. Instead, received: '${ kindOf (
@@ -114,7 +113,7 @@ export function createStore<S, A extends Action, Ext = {}, StateExt = never>(
114113 return enhancer ( createStore ) (
115114 reducer ,
116115 preloadedState as PreloadedState < S >
117- ) as Store < ExtendState < S , StateExt > , A , StateExt , Ext > & Ext
116+ ) as Store < S , A , StateExt > & Ext
118117 }
119118
120119 let currentReducer = reducer
@@ -288,11 +287,8 @@ export function createStore<S, A extends Action, Ext = {}, StateExt = never>(
288287 * implement a hot reloading mechanism for Redux.
289288 *
290289 * @param nextReducer The reducer for the store to use instead.
291- * @returns The same store instance with a new reducer in place.
292290 */
293- function replaceReducer < NewState , NewActions extends A > (
294- nextReducer : Reducer < NewState , NewActions >
295- ) : Store < ExtendState < NewState , StateExt > , NewActions , StateExt , Ext > & Ext {
291+ function replaceReducer ( nextReducer : Reducer < S , A > ) : void {
296292 if ( typeof nextReducer !== 'function' ) {
297293 throw new Error (
298294 `Expected the nextReducer to be a function. Instead, received: '${ kindOf (
@@ -301,22 +297,13 @@ export function createStore<S, A extends Action, Ext = {}, StateExt = never>(
301297 )
302298 }
303299
304- // TODO: do this more elegantly
305- ; ( currentReducer as unknown as Reducer < NewState , NewActions > ) = nextReducer
300+ currentReducer = nextReducer
306301
307302 // This action has a similar effect to ActionTypes.INIT.
308303 // Any reducers that existed in both the new and old rootReducer
309304 // will receive the previous state. This effectively populates
310305 // the new state tree with any relevant data from the old one.
311306 dispatch ( { type : ActionTypes . REPLACE } as A )
312- // change the type of the store by casting it to the new store
313- return store as unknown as Store <
314- ExtendState < NewState , StateExt > ,
315- NewActions ,
316- StateExt ,
317- Ext
318- > &
319- Ext
320307 }
321308
322309 /**
@@ -374,7 +361,7 @@ export function createStore<S, A extends Action, Ext = {}, StateExt = never>(
374361 getState,
375362 replaceReducer,
376363 [ $$observable ] : observable
377- } as unknown as Store < ExtendState < S , StateExt > , A , StateExt , Ext > & Ext
364+ } as unknown as Store < S , A , StateExt > & Ext
378365 return store
379366}
380367
@@ -416,7 +403,7 @@ export function legacy_createStore<
416403> (
417404 reducer : Reducer < S , A > ,
418405 enhancer ?: StoreEnhancer < Ext , StateExt >
419- ) : Store < ExtendState < S , StateExt > , A , StateExt , Ext > & Ext
406+ ) : Store < S , A , StateExt > & Ext
420407/**
421408 * Creates a Redux store that holds the state tree.
422409 *
@@ -456,7 +443,7 @@ export function legacy_createStore<
456443 reducer : Reducer < S , A > ,
457444 preloadedState ?: PreloadedState < S > ,
458445 enhancer ?: StoreEnhancer < Ext , StateExt >
459- ) : Store < ExtendState < S , StateExt > , A , StateExt , Ext > & Ext
446+ ) : Store < S , A , StateExt > & Ext
460447export function legacy_createStore <
461448 S ,
462449 A extends Action ,
@@ -466,6 +453,6 @@ export function legacy_createStore<
466453 reducer : Reducer < S , A > ,
467454 preloadedState ?: PreloadedState < S > | StoreEnhancer < Ext , StateExt > ,
468455 enhancer ?: StoreEnhancer < Ext , StateExt >
469- ) : Store < ExtendState < S , StateExt > , A , StateExt , Ext > & Ext {
456+ ) : Store < S , A , StateExt > & Ext {
470457 return createStore ( reducer , preloadedState as any , enhancer )
471458}
0 commit comments