I'm doing a redux-toolkit tutorial with typescript. But I'm a typescript beginner.
I don't know what the problem is here. Please give me your insight.
This is an error message. : TS2322: Type 'number' is not assignable to type 'void | State | WritableDraft'.
import {CaseReducer, createSlice, PayloadAction} from "@reduxjs/toolkit";
type State = {
value: number
}
const increment: CaseReducer<State,PayloadAction<number>> = (state, action) => state.value + action.payload; // error line
export const counterSlice = createSlice({
name: 'counter',
initialState: {
value: 0
},
reducers: {
increment,
decrement: state => {
state.value -= 1
},
incrementByAmount: (state, action) => {
state.value += action.payload
},
},
})
export const {increment, decrement, incrementByAmount} = counterSlice.actions;
export default counterSlice.reducer;