簡體   English   中英

Typescript 顯示錯誤,即使它在 VSCode 上編譯也是如此

[英]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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM