5
5
PreloadedState ,
6
6
StoreEnhancer ,
7
7
Dispatch ,
8
- Observer ,
9
- ExtendState
8
+ Observer
10
9
} from './types/store'
11
10
import { Action } from './types/actions'
12
11
import { Reducer } from './types/reducers'
@@ -42,7 +41,7 @@ import { kindOf } from './utils/kindOf'
42
41
export function createStore < S , A extends Action , Ext = { } , StateExt = never > (
43
42
reducer : Reducer < S , A > ,
44
43
enhancer ?: StoreEnhancer < Ext , StateExt >
45
- ) : Store < ExtendState < S , StateExt > , A , StateExt , Ext > & Ext
44
+ ) : Store < S , A , StateExt > & Ext
46
45
/**
47
46
* @deprecated
48
47
*
@@ -72,12 +71,12 @@ export function createStore<S, A extends Action, Ext = {}, StateExt = never>(
72
71
reducer : Reducer < S , A > ,
73
72
preloadedState ?: PreloadedState < S > ,
74
73
enhancer ?: StoreEnhancer < Ext , StateExt >
75
- ) : Store < ExtendState < S , StateExt > , A , StateExt , Ext > & Ext
74
+ ) : Store < S , A , StateExt > & Ext
76
75
export function createStore < S , A extends Action , Ext = { } , StateExt = never > (
77
76
reducer : Reducer < S , A > ,
78
77
preloadedState ?: PreloadedState < S > | StoreEnhancer < Ext , StateExt > ,
79
78
enhancer ?: StoreEnhancer < Ext , StateExt >
80
- ) : Store < ExtendState < S , StateExt > , A , StateExt , Ext > & Ext {
79
+ ) : Store < S , A , StateExt > & Ext {
81
80
if ( typeof reducer !== 'function' ) {
82
81
throw new Error (
83
82
`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>(
114
113
return enhancer ( createStore ) (
115
114
reducer ,
116
115
preloadedState as PreloadedState < S >
117
- ) as Store < ExtendState < S , StateExt > , A , StateExt , Ext > & Ext
116
+ ) as Store < S , A , StateExt > & Ext
118
117
}
119
118
120
119
let currentReducer = reducer
@@ -288,11 +287,8 @@ export function createStore<S, A extends Action, Ext = {}, StateExt = never>(
288
287
* implement a hot reloading mechanism for Redux.
289
288
*
290
289
* @param nextReducer The reducer for the store to use instead.
291
- * @returns The same store instance with a new reducer in place.
292
290
*/
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 {
296
292
if ( typeof nextReducer !== 'function' ) {
297
293
throw new Error (
298
294
`Expected the nextReducer to be a function. Instead, received: '${ kindOf (
@@ -301,22 +297,13 @@ export function createStore<S, A extends Action, Ext = {}, StateExt = never>(
301
297
)
302
298
}
303
299
304
- // TODO: do this more elegantly
305
- ; ( currentReducer as unknown as Reducer < NewState , NewActions > ) = nextReducer
300
+ currentReducer = nextReducer
306
301
307
302
// This action has a similar effect to ActionTypes.INIT.
308
303
// Any reducers that existed in both the new and old rootReducer
309
304
// will receive the previous state. This effectively populates
310
305
// the new state tree with any relevant data from the old one.
311
306
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
320
307
}
321
308
322
309
/**
@@ -374,7 +361,7 @@ export function createStore<S, A extends Action, Ext = {}, StateExt = never>(
374
361
getState,
375
362
replaceReducer,
376
363
[ $$observable ] : observable
377
- } as unknown as Store < ExtendState < S , StateExt > , A , StateExt , Ext > & Ext
364
+ } as unknown as Store < S , A , StateExt > & Ext
378
365
return store
379
366
}
380
367
@@ -416,7 +403,7 @@ export function legacy_createStore<
416
403
> (
417
404
reducer : Reducer < S , A > ,
418
405
enhancer ?: StoreEnhancer < Ext , StateExt >
419
- ) : Store < ExtendState < S , StateExt > , A , StateExt , Ext > & Ext
406
+ ) : Store < S , A , StateExt > & Ext
420
407
/**
421
408
* Creates a Redux store that holds the state tree.
422
409
*
@@ -456,7 +443,7 @@ export function legacy_createStore<
456
443
reducer : Reducer < S , A > ,
457
444
preloadedState ?: PreloadedState < S > ,
458
445
enhancer ?: StoreEnhancer < Ext , StateExt >
459
- ) : Store < ExtendState < S , StateExt > , A , StateExt , Ext > & Ext
446
+ ) : Store < S , A , StateExt > & Ext
460
447
export function legacy_createStore <
461
448
S ,
462
449
A extends Action ,
@@ -466,6 +453,6 @@ export function legacy_createStore<
466
453
reducer : Reducer < S , A > ,
467
454
preloadedState ?: PreloadedState < S > | StoreEnhancer < Ext , StateExt > ,
468
455
enhancer ?: StoreEnhancer < Ext , StateExt >
469
- ) : Store < ExtendState < S , StateExt > , A , StateExt , Ext > & Ext {
456
+ ) : Store < S , A , StateExt > & Ext {
470
457
return createStore ( reducer , preloadedState as any , enhancer )
471
458
}
0 commit comments