Использую React + Redux Toolkit + Typescript.
Редюсер выглядит так:
import { createSlice } from '@reduxjs/toolkit';
interface IRootState {
test: boolean;
}
const initialState: IRootState = {
test: true,
};
export const mainReducer = createSlice({
name: 'mainReducer',
initialState,
reducers: {
testSwitcher(state) {
state.test = !state.test;
},
},
});
export const { testSwitcher } = mainReducer.actions;
export default mainReducer.reducer;
store выглядит так:
const store = configureStore({
reducer: {
main: mainReducer,
},
devTools: process.env.NODE_ENV !== 'production',
});
Импорт стейта в компоненте:
const { test } = useSelector((state) => state.main);
В результате typescript показывает ошибку в state.main:
Property 'main' does not exist on type 'DefaultRootState'
Как это исправить?