[英]Typescript shows an error even though it compiles on VSCode
我將 react-redux 與 typescript 一起使用,當我在 Slice 中定義減速器時,VSCode 顯示此錯誤,即使它可以編譯並且一切正常。
這是完整的代碼:
//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
用npm
重新安裝軟件包解決了這個問題。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.