简体   繁体   English

Typescript 显示错误,即使它在 VSCode 上编译也是如此

[英]Typescript shows an error even though it compiles on VSCode

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.我将 react-redux 与 typescript 一起使用,当我在 Slice 中定义减速器时,VSCode 显示此错误,即使它可以编译并且一切正常。

错误信息

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

SOLVED解决了

Reinstalling the packages with npm solved the problem.npm重新安装软件包解决了这个问题。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM