I'm using react-redux with typescript and when I define a reducer inside a Slice VSCode shows this error even though it compiles and everything works.
Here's the full code:
//counterSlice.ts
import { createSlice, PayloadAction } from '@reduxjs/toolkit'
export interface CounterState {
value: number
}
const initialState: CounterState = {
value: 0
}
export const counterSlice = createSlice({
name: 'counter',
initialState,
reducers: {
incrementByAmount: (state, action: PayloadAction<number>) => {
state.value += action.payload
}
}
})
export const { incrementByAmount } = counterSlice.actions
export default counterSlice.reducer
Reinstalling the packages with npm
solved the problem.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.