Skip to content

Instantly share code, notes, and snippets.

@fdjones
Last active January 5, 2020 10:55
Show Gist options
  • Save fdjones/4fbd7c2bed92ecf15d299db47efccc72 to your computer and use it in GitHub Desktop.
Save fdjones/4fbd7c2bed92ecf15d299db47efccc72 to your computer and use it in GitHub Desktop.
// 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