@@ -44,15 +44,13 @@ export interface ConfigureStoreOptions<
44
44
A extends Action = AnyAction ,
45
45
M extends Middlewares < S > = Middlewares < S > ,
46
46
E extends Enhancers = Enhancers ,
47
- PreloadedState = S
47
+ P = S
48
48
> {
49
49
/**
50
50
* A single reducer function that will be used as the root reducer, or an
51
51
* object of slice reducers that will be passed to `combineReducers()`.
52
52
*/
53
- reducer :
54
- | Reducer < S , A , PreloadedState >
55
- | ReducersMapObject < S , A , PreloadedState >
53
+ reducer : Reducer < S , A , P > | ReducersMapObject < S , A , P >
56
54
57
55
/**
58
56
* An array of Redux middleware to install. If not supplied, defaults to
@@ -78,16 +76,8 @@ export interface ConfigureStoreOptions<
78
76
* function (either directly or indirectly by passing an object as `reducer`),
79
77
* this must be an object with the same shape as the reducer map keys.
80
78
*/
81
- /*
82
- Not 100% correct but the best approximation we can get:
83
- - if S is a `CombinedState` applying a second `CombinedState` on it does not change anything.
84
- - if it is not, there could be two cases:
85
- - `ReducersMapObject<S, A>` is being passed in. In this case, we will call `combineReducers` on it and `CombinedState<S>` is correct
86
- - `Reducer<S, A>` is being passed in. In this case, actually `CombinedState<S>` is wrong and `S` would be correct.
87
- As we cannot distinguish between those two cases without adding another generic parameter,
88
- we just make the pragmatic assumption that the latter almost never happens.
89
- */
90
- preloadedState ?: PreloadedState
79
+ // we infer here, and instead complain if the reducer doesn't match
80
+ preloadedState ?: P
91
81
92
82
/**
93
83
* The store enhancers to apply. See Redux's `createStore()`.
@@ -143,10 +133,8 @@ export function configureStore<
143
133
A extends Action = AnyAction ,
144
134
M extends Middlewares < S > = [ ThunkMiddlewareFor < S > ] ,
145
135
E extends Enhancers = [ StoreEnhancer ] ,
146
- PreloadedState = S
147
- > (
148
- options : ConfigureStoreOptions < S , A , M , E , PreloadedState >
149
- ) : EnhancedStore < S , A , M , E > {
136
+ P = S
137
+ > ( options : ConfigureStoreOptions < S , A , M , E , P > ) : EnhancedStore < S , A , M , E > {
150
138
const curriedGetDefaultMiddleware = curryGetDefaultMiddleware < S > ( )
151
139
152
140
const {
@@ -157,16 +145,12 @@ export function configureStore<
157
145
enhancers = undefined ,
158
146
} = options || { }
159
147
160
- let rootReducer : Reducer < S , A , PreloadedState >
148
+ let rootReducer : Reducer < S , A , P >
161
149
162
150
if ( typeof reducer === 'function' ) {
163
151
rootReducer = reducer
164
152
} else if ( isPlainObject ( reducer ) ) {
165
- rootReducer = combineReducers ( reducer ) as unknown as Reducer <
166
- S ,
167
- A ,
168
- PreloadedState
169
- >
153
+ rootReducer = combineReducers ( reducer ) as unknown as Reducer < S , A , P >
170
154
} else {
171
155
throw new Error (
172
156
'"reducer" is a required argument, and must be a function or an object of functions that can be passed to combineReducers'
0 commit comments