Skip to content

Commit f53c208

Browse files
committed
change type
1 parent 501f579 commit f53c208

File tree

2 files changed

+20
-5
lines changed

2 files changed

+20
-5
lines changed

etc/redux-toolkit.api.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,10 @@
77
import { Action } from 'redux';
88
import { ActionCreator } from 'redux';
99
import { AnyAction } from 'redux';
10+
import { CombinedState } from 'redux';
1011
import { default as createNextState } from 'immer';
1112
import { createSelector } from 'reselect';
1213
import { current } from 'immer';
13-
import { DeepPartial } from 'redux';
1414
import { Dispatch } from 'redux';
1515
import { Draft } from 'immer';
1616
import { freeze } from 'immer';
@@ -20,6 +20,7 @@ import { original } from 'immer';
2020
import { OutputParametricSelector } from 'reselect';
2121
import { OutputSelector } from 'reselect';
2222
import { ParametricSelector } from 'reselect';
23+
import { PreloadedState } from 'redux';
2324
import { Reducer } from 'redux';
2425
import { ReducersMapObject } from 'redux';
2526
import { Selector } from 'reselect';
@@ -127,7 +128,7 @@ export interface ConfigureStoreOptions<S = any, A extends Action = AnyAction, M
127128
devTools?: boolean | EnhancerOptions;
128129
enhancers?: StoreEnhancer[] | ConfigureEnhancersCallback;
129130
middleware?: ((getDefaultMiddleware: CurriedGetDefaultMiddleware<S>) => M) | M;
130-
preloadedState?: DeepPartial<S extends any ? S : S>;
131+
preloadedState?: PreloadedState<CombinedState<NoInfer<S>>>;
131132
reducer: Reducer<S, A> | ReducersMapObject<S, A>;
132133
}
133134

src/configureStore.ts

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,8 @@ import {
1111
StoreEnhancer,
1212
Store,
1313
Dispatch,
14-
PreloadedState
14+
PreloadedState,
15+
CombinedState
1516
} from 'redux'
1617
import {
1718
composeWithDevTools,
@@ -74,7 +75,16 @@ export interface ConfigureStoreOptions<
7475
* function (either directly or indirectly by passing an object as `reducer`),
7576
* this must be an object with the same shape as the reducer map keys.
7677
*/
77-
preloadedState?: PreloadedState<NoInfer<S>>
78+
/*
79+
Not 100% correct but the best approximation we can get:
80+
- if S is a `CombinedState` we know it is from a `combineReducers` call and we can just apply `PreloadedState` on it.
81+
- if it is not, there could be two cases:
82+
- `ReducersMapObject<S, A>` is being passed in. In this case, we will call `combineReducers` on it and `Partial<S>` is correct
83+
- `Reducer<S, A>` is being passed in. In this case, actually `Partial<S>` is wrong and `S` would be correct.
84+
As we cannot distinguish between those two cases without adding another generic paramter,
85+
we just make the pragmatic assumption that the latter almost never happens.
86+
*/
87+
preloadedState?: PreloadedState<CombinedState<NoInfer<S>>>
7888

7989
/**
8090
* The store enhancers to apply. See Redux's `createStore()`.
@@ -169,5 +179,9 @@ export function configureStore<
169179

170180
const composedEnhancer = finalCompose(...storeEnhancers) as any
171181

172-
return createStore(rootReducer, preloadedState, composedEnhancer)
182+
return createStore(
183+
rootReducer,
184+
preloadedState as PreloadedState<S> | undefined,
185+
composedEnhancer
186+
)
173187
}

0 commit comments

Comments
 (0)