react-typescript-taskify
react-typescript-taskify copied to clipboard
Getting error in handleEdit
trafficstars
Getting the following error: ERROR in src/Components/Task.tsx:29:18
TS2345: Argument of type '(TaskDo | { todo: string; length: number; toString(): string; toLocaleString(): string; pop(): TaskDo | undefined; push(...items: TaskDo[]): number; concat(...items: ConcatArray<...>[]): TaskDo[]; concat(...items: (TaskDo | ConcatArray<...>)[]): TaskDo[]; ... 28 more ...; [Symbol.unscopables](): { ...; }; })[]' is not assignable to parameter of type 'SetStateAction<TaskDo[]>'.
Type '(TaskDo | { todo: string; length: number; toString(): string; toLocaleString(): string; pop(): TaskDo | undefined; push(...items: TaskDo[]): number; concat(...items: ConcatArray<...>[]): TaskDo[]; concat(...items: (TaskDo | ConcatArray<...>)[]): TaskDo[]; ... 28 more ...; [Symbol.unscopables](): { ...; }; })[]' is not assignable to type 'TaskDo[]'.
Type 'TaskDo | { todo: string; length: number; toString(): string; toLocaleString(): string; pop(): TaskDo | undefined; push(...items: TaskDo[]): number; concat(...items: ConcatArray<...>[]): TaskDo[]; concat(...items: (TaskDo | ConcatArray<...>)[]): TaskDo[]; ... 28 more ...; [Symbol.unscopables](): { ...; }; }' is not assignable to type 'TaskDo'.
Type '{ todo: string; length: number; toString(): string; toLocaleString(): string; pop(): TaskDo | undefined; push(...items: TaskDo[]): number; concat(...items: ConcatArray<TaskDo>[]): TaskDo[]; concat(...items: (TaskDo | ConcatArray<...>)[]): TaskDo[]; ... 28 more ...; [Symbol.unscopables](): { ...; }; }' is missing the following properties from type 'TaskDo': id, isDone
27 | const handleEdit = (e:React.FormEvent,id:number)=>{
28 | e.preventDefault();
> 29 | setTasks(tasks.map((task) => task.id === id ? { ...tasks, todo: editTask } : task));
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
30 | setEdit(false);
31 | }
32 |
My Code:-
const handleEdit = (e:React.FormEvent,id:number)=>{
e.preventDefault();
**setTasks(tasks.map((task) => task.id === id ? { ...tasks, todo: editTask } : task));** //ERROR
setEdit(false);
}
@piyush-eon : Kindly advise on this 🙏🙏🙏 src.zip
Based on the code in line 29 "tasks" is not defined, you should pass "...task" instead of "...tasks" like:
- setTasks(tasks.map((task) => task.id === id ? { ...task, todo: editTask } : task)); // fix