Skip to content

Commit 7b0502d

Browse files
committed
Fix configureStore() state inference without extra type
Thanks to @Dudeonyx for this hack.
1 parent da97831 commit 7b0502d

File tree

1 file changed

+9
-11
lines changed

1 file changed

+9
-11
lines changed

src/configureStore.ts

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -47,11 +47,7 @@ export function getDefaultMiddleware(
4747
/**
4848
* Options for `configureStore()`.
4949
*/
50-
export interface ConfigureStoreOptions<
51-
S = any,
52-
A extends Action = AnyAction,
53-
PS extends S = S
54-
> {
50+
export interface ConfigureStoreOptions<S = any, A extends Action = AnyAction> {
5551
/**
5652
* A single reducer function that will be used as the root reducer, or an
5753
* object of slice reducers that will be passed to `combineReducers()`.
@@ -76,7 +72,11 @@ export interface ConfigureStoreOptions<
7672
* function (either directly or indirectly by passing an object as `reducer`),
7773
* this must be an object with the same shape as the reducer map keys.
7874
*/
79-
preloadedState?: DeepPartial<PS>
75+
// NOTE: The needlessly complicated `S extends any ? S : S` instead of just
76+
// `S` ensures that the TypeScript compiler doesn't attempt to infer `S`
77+
// based on the value passed as `preloadedState`, which might be a partial
78+
// state rather than the full thing.
79+
preloadedState?: DeepPartial<S extends any ? S : S>
8080

8181
/**
8282
* The store enhancers to apply. See Redux's `createStore()`. If you only
@@ -91,11 +91,9 @@ export interface ConfigureStoreOptions<
9191
* @param config The store configuration.
9292
* @returns A configured Redux store.
9393
*/
94-
export function configureStore<
95-
S = any,
96-
A extends Action = AnyAction,
97-
PS extends S = S
98-
>(options: ConfigureStoreOptions<S, A, PS>): Store<S, A> {
94+
export function configureStore<S = any, A extends Action = AnyAction>(
95+
options: ConfigureStoreOptions<S, A>
96+
): Store<S, A> {
9997
const {
10098
reducer = undefined,
10199
middleware = getDefaultMiddleware(),

0 commit comments

Comments
 (0)