-
-
Save fdjones/4fbd7c2bed92ecf15d299db47efccc72 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// doesn't work | |
import { createSlice, PayloadAction } from "@reduxjs/toolkit"; | |
const todo = createSlice({ | |
name: "todo", | |
initialState: [], | |
reducers: { | |
add: (state, action: PayloadAction<string>) => { | |
state.push(action.payload); // Argument of type 'string' is not assignable to parameter of type 'never'.ts(2345) | |
} | |
}); | |
// works | |
import { createSlice, PayloadAction } from "@reduxjs/toolkit"; | |
interface Todo { | |
id: number; | |
task: string; | |
} | |
const initialState: Todo[] = []; | |
const todo = createSlice({ | |
name: "todo", | |
initialState: initialState, | |
reducers: { | |
add: (state, action: PayloadAction<Todo>) => { | |
state.push(action.payload); | |
} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment