Still trying to learn this typing system not sure if it's possible.
I'm working with redux and the redux toolkit, and it's mentioned that after creating the redux store, you can create a typed version of the store's dispatch and state.
Directly from their site:
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
My question is that I need to defer configuration of the store.
import { configureStore } from '@reduxjs/toolkit'
// ...
const createStore = () => configureStore({
reducer: {
one: oneSlice.reducer,
two: twoSlice.reducer
}
});
// in some other class ///
const store = createStore();
Is there anyway to get the types mentioned from the first method to actually be used within code?
edit
I am looking to be able to annotate the store constant in the last example.