简体   繁体   中英

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.

错误信息

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.

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.

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