-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Closed as not planned
Description
I tried to create a lib which contains simple Slice. If I include the file in the app project directly, it works.
But, if I build a lib which includes the file and add dependency of it, the app reports error
Type 'typeof import("/Users/user/temp/redux-toolkit-app/node_modules/my-redux-lib/dist/types")' is not assignable to type 'Reducer<unknown, AnyAction>'.
Type 'typeof import("/Users/user/temp/redux-toolkit-app/node_modules/my-redux-lib/dist/types")' provides no match for the signature '(state: unknown, action: AnyAction): unknown'.ts(2322)
Main codes,
// store.ts
import counterReducer from '../features/counter/counterSlice';
import libCounterReducer from 'my-redux-lib';
export const store = configureStore({
reducer: {
counter: counterReducer,
libcounter: libCounterReducer, // error here
},
});
// counterSlice
export interface CounterState {
value: number;
}
const initialState: CounterState = {
value: 0,
};
export const counterSlice = createSlice({
name: 'counter',
initialState,
reducers: {
increment: (state) => {
state.value += 1;
},
},
});
export const { increment } = counterSlice.actions;
export const selectCount = (state: RootState) => state.counter.value;
export default counterSlice.reducer;
// libCountSlice
export interface LibCounterState {
value: number;
}
const initialState: LibCounterState = {
value: 0,
};
export interface Store {
libcounter: unknown | LibCounterState
}
export const libCounterSlice = createSlice({
name: 'libcounter',
initialState,
reducers: {
increment: (state) => {
state.value += 1;
},
},
});
export const { increment } = libCounterSlice.actions;
export const selectCount = (state: Store) => (state.libcounter as LibCounterState).value;
export default libCounterSlice.reducer;
Metadata
Metadata
Assignees
Labels
No labels