繁体   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