6
6
StoreEnhancer ,
7
7
Dispatch ,
8
8
Observer ,
9
- ExtendState ,
10
9
ListenerCallback
11
10
} from './types/store'
12
11
import { Action } from './types/actions'
@@ -43,7 +42,7 @@ import { kindOf } from './utils/kindOf'
43
42
export function createStore < S , A extends Action , Ext = { } , StateExt = never > (
44
43
reducer : Reducer < S , A > ,
45
44
enhancer ?: StoreEnhancer < Ext , StateExt >
46
- ) : Store < ExtendState < S , StateExt > , A , StateExt , Ext > & Ext
45
+ ) : Store < S , A , StateExt > & Ext
47
46
/**
48
47
* @deprecated
49
48
*
@@ -73,12 +72,12 @@ export function createStore<S, A extends Action, Ext = {}, StateExt = never>(
73
72
reducer : Reducer < S , A > ,
74
73
preloadedState ?: PreloadedState < S > ,
75
74
enhancer ?: StoreEnhancer < Ext , StateExt >
76
- ) : Store < ExtendState < S , StateExt > , A , StateExt , Ext > & Ext
75
+ ) : Store < S , A , StateExt > & Ext
77
76
export function createStore < S , A extends Action , Ext = { } , StateExt = never > (
78
77
reducer : Reducer < S , A > ,
79
78
preloadedState ?: PreloadedState < S > | StoreEnhancer < Ext , StateExt > ,
80
79
enhancer ?: StoreEnhancer < Ext , StateExt >
81
- ) : Store < ExtendState < S , StateExt > , A , StateExt , Ext > & Ext {
80
+ ) : Store < S , A , StateExt > & Ext {
82
81
if ( typeof reducer !== 'function' ) {
83
82
throw new Error (
84
83
`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>(
115
114
return enhancer ( createStore ) (
116
115
reducer ,
117
116
preloadedState as PreloadedState < S >
118
- ) as Store < ExtendState < S , StateExt > , A , StateExt , Ext > & Ext
117
+ ) as Store < S , A , StateExt > & Ext
119
118
}
120
119
121
120
let currentReducer = reducer
@@ -291,11 +290,8 @@ export function createStore<S, A extends Action, Ext = {}, StateExt = never>(
291
290
* implement a hot reloading mechanism for Redux.
292
291
*
293
292
* @param nextReducer The reducer for the store to use instead.
294
- * @returns The same store instance with a new reducer in place.
295
293
*/
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 {
299
295
if ( typeof nextReducer !== 'function' ) {
300
296
throw new Error (
301
297
`Expected the nextReducer to be a function. Instead, received: '${ kindOf (
@@ -304,22 +300,13 @@ export function createStore<S, A extends Action, Ext = {}, StateExt = never>(
304
300
)
305
301
}
306
302
307
- // TODO: do this more elegantly
308
- ; ( currentReducer as unknown as Reducer < NewState , NewActions > ) = nextReducer
303
+ currentReducer = nextReducer
309
304
310
305
// This action has a similar effect to ActionTypes.INIT.
311
306
// Any reducers that existed in both the new and old rootReducer
312
307
// will receive the previous state. This effectively populates
313
308
// the new state tree with any relevant data from the old one.
314
309
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
323
310
}
324
311
325
312
/**
@@ -377,7 +364,7 @@ export function createStore<S, A extends Action, Ext = {}, StateExt = never>(
377
364
getState,
378
365
replaceReducer,
379
366
[ $$observable ] : observable
380
- } as unknown as Store < ExtendState < S , StateExt > , A , StateExt , Ext > & Ext
367
+ } as unknown as Store < S , A , StateExt > & Ext
381
368
return store
382
369
}
383
370
@@ -419,7 +406,7 @@ export function legacy_createStore<
419
406
> (
420
407
reducer : Reducer < S , A > ,
421
408
enhancer ?: StoreEnhancer < Ext , StateExt >
422
- ) : Store < ExtendState < S , StateExt > , A , StateExt , Ext > & Ext
409
+ ) : Store < S , A , StateExt > & Ext
423
410
/**
424
411
* Creates a Redux store that holds the state tree.
425
412
*
@@ -459,7 +446,7 @@ export function legacy_createStore<
459
446
reducer : Reducer < S , A > ,
460
447
preloadedState ?: PreloadedState < S > ,
461
448
enhancer ?: StoreEnhancer < Ext , StateExt >
462
- ) : Store < ExtendState < S , StateExt > , A , StateExt , Ext > & Ext
449
+ ) : Store < S , A , StateExt > & Ext
463
450
export function legacy_createStore <
464
451
S ,
465
452
A extends Action ,
@@ -469,6 +456,6 @@ export function legacy_createStore<
469
456
reducer : Reducer < S , A > ,
470
457
preloadedState ?: PreloadedState < S > | StoreEnhancer < Ext , StateExt > ,
471
458
enhancer ?: StoreEnhancer < Ext , StateExt >
472
- ) : Store < ExtendState < S , StateExt > , A , StateExt , Ext > & Ext {
459
+ ) : Store < S , A , StateExt > & Ext {
473
460
return createStore ( reducer , preloadedState as any , enhancer )
474
461
}
0 commit comments