Skip to content

Getting error in handleEdit  #6

@guruprakash-c

Description

@guruprakash-c

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions