我正在尝试使用类型来配置具有预加载状态的 Redux 存储。
在终极版工具包typescript快速入门指南有这个例子:
import { configureStore } from '@reduxjs/toolkit'
const store = configureStore({
reducer: {
one: oneSlice.reducer,
two: twoSlice.reducer
}
})
// Infer the `RootState` and `AppDispatch` types from the store itself
export type RootState = ReturnType<typeof store.getState>
export type AppDispatch = typeof store.dispatch
不幸的是,在预加载状态下,它看起来更像这样:
export function initStore(preloadedState) {
const store = configureStore({
reducer: {
one: oneSlice.reducer,
two: twoSlice.reducer
},
preloadedState,
})
return store
}
我现在从哪里获得RootState
类型和AppDispatch
类型?