@@ -7,8 +7,6 @@ import type {
7
7
StoreEnhancer ,
8
8
Store ,
9
9
Dispatch ,
10
- PreloadedState ,
11
- CombinedState ,
12
10
} from 'redux'
13
11
import { createStore , compose , applyMiddleware , combineReducers } from 'redux'
14
12
import type { DevToolsEnhancerOptions as DevToolsOptions } from './devtoolsExtension'
@@ -21,7 +19,6 @@ import type {
21
19
} from './getDefaultMiddleware'
22
20
import { curryGetDefaultMiddleware } from './getDefaultMiddleware'
23
21
import type {
24
- NoInfer ,
25
22
ExtractDispatchExtensions ,
26
23
ExtractStoreExtensions ,
27
24
} from './tsHelpers'
@@ -45,14 +42,17 @@ export type ConfigureEnhancersCallback<E extends Enhancers = Enhancers> = (
45
42
export interface ConfigureStoreOptions <
46
43
S = any ,
47
44
A extends Action = AnyAction ,
45
+ PreloadedState = S ,
48
46
M extends Middlewares < S > = Middlewares < S > ,
49
47
E extends Enhancers = Enhancers
50
48
> {
51
49
/**
52
50
* A single reducer function that will be used as the root reducer, or an
53
51
* object of slice reducers that will be passed to `combineReducers()`.
54
52
*/
55
- reducer : Reducer < S , A > | ReducersMapObject < S , A >
53
+ reducer :
54
+ | Reducer < S , A , PreloadedState >
55
+ | ReducersMapObject < S , A , PreloadedState >
56
56
57
57
/**
58
58
* An array of Redux middleware to install. If not supplied, defaults to
@@ -87,7 +87,7 @@ export interface ConfigureStoreOptions<
87
87
As we cannot distinguish between those two cases without adding another generic parameter,
88
88
we just make the pragmatic assumption that the latter almost never happens.
89
89
*/
90
- preloadedState ?: PreloadedState < CombinedState < NoInfer < S > > >
90
+ preloadedState ?: PreloadedState
91
91
92
92
/**
93
93
* The store enhancers to apply. See Redux's `createStore()`.
@@ -141,9 +141,12 @@ export type EnhancedStore<
141
141
export function configureStore <
142
142
S = any ,
143
143
A extends Action = AnyAction ,
144
+ PreloadedState = S ,
144
145
M extends Middlewares < S > = [ ThunkMiddlewareFor < S > ] ,
145
146
E extends Enhancers = [ StoreEnhancer ]
146
- > ( options : ConfigureStoreOptions < S , A , M , E > ) : EnhancedStore < S , A , M , E > {
147
+ > (
148
+ options : ConfigureStoreOptions < S , A , PreloadedState , M , E >
149
+ ) : EnhancedStore < S , A , M , E > {
147
150
const curriedGetDefaultMiddleware = curryGetDefaultMiddleware < S > ( )
148
151
149
152
const {
@@ -154,12 +157,16 @@ export function configureStore<
154
157
enhancers = undefined ,
155
158
} = options || { }
156
159
157
- let rootReducer : Reducer < S , A >
160
+ let rootReducer : Reducer < S , A , PreloadedState >
158
161
159
162
if ( typeof reducer === 'function' ) {
160
163
rootReducer = reducer
161
164
} else if ( isPlainObject ( reducer ) ) {
162
- rootReducer = combineReducers ( reducer ) as unknown as Reducer < S , A >
165
+ rootReducer = combineReducers ( reducer ) as unknown as Reducer <
166
+ S ,
167
+ A ,
168
+ PreloadedState
169
+ >
163
170
} else {
164
171
throw new Error (
165
172
'"reducer" is a required argument, and must be a function or an object of functions that can be passed to combineReducers'
0 commit comments