Today when I build the project, shows error:
> [email protected] build
> tsc && vite build
src/redux/store/store.ts:7:5 - error TS2322: Type 'Reducer<CombinedState<{ projShare: { collar: any; }; }>, any>' is not assignable to type 'Reducer<CombinedState<{ projShare: { collar: any; }; }>, any, {}> | { readonly [$CombinedState]?: Reducer<undefined, any, never> | undefined; projShare: Reducer<...>; }'.
Type 'Reducer<CombinedState<{ projShare: { collar: any; }; }>, any>' is not assignable to type 'Reducer<CombinedState<{ projShare: { collar: any; }; }>, any, {}>'.
Types of parameters 'state' and 'state' are incompatible.
Type 'CombinedState<{ projShare: { collar: any; }; }> | {} | undefined' is not assignable to type 'CombinedState<{ projShare: { collar: any; }; }> | undefined'.
Type '{}' is not assignable to type 'CombinedState<{ projShare: { collar: any; }; }>'.
Property 'projShare' is missing in type '{}' but required in type '{ projShare: { collar: any; }; }'.
7 reducer: rootReducer,
~~~~~~~
src/redux/reducer/combineReducer.ts:15:5
15 projShare
~~~~~~~~~
'projShare' is declared here.
node_modules/@reduxjs/toolkit/dist/index.d.ts:538:5
538 reducer: Reducer<S, A, P> | ReducersMapObject<S, A, P>;
~~~~~~~
The expected type comes from property 'reducer' which is declared here on type 'ConfigureStoreOptions<CombinedState<{ projShare: { collar: any; }; }>, any, Tuple<[ThunkMiddleware<CombinedState<{ projShare: { collar: any; }; }>, UnknownAction, undefined>]>, Tuple<...>, {}>'
Found 1 error in src/redux/store/store.ts:7
Now I am using "redux": "^4.2.1"
, this is the store.ts
defined like:
import { configureStore } from '@reduxjs/toolkit';
import rootReducer from '@/redux/reducer/combineReducer';
const initialState = {};
const store = configureStore({
reducer: rootReducer,
// middleware: [thunk],
devTools: process.env.NODE_ENV !== 'production',
preloadedState: initialState
});
export default store;
and this is the root reducer defined like:
import { combineReducers } from 'redux';
import projShare from "@/redux/reducer/project/ProjectShareReducer";
const rootReducer = combineReducers({
projShare
});
export default rootReducer;
this is the project reducer defined like:
import { ProjCollarModel } from "@/model/proj/share/ProjCollarModel";
import { AppState } from "@/redux/types/AppState";
const initState: AppState["projShare"] = {
collar: {} as ProjCollarModel[],
};
const ProjectShareReducer = (state = initState, action: any) => {
switch (action.type) {
case "GET_COLLAR_USERS":
return {
...state,
collar: action.data
};
default:
break;
}
return state;
};
export default ProjectShareReducer;
Am I missing something? what should I do to fixed this issue? I have already tried to update the version to latest like this:
npm install @reduxjs/toolkit@latest @types/react-redux@latest