简体   繁体   中英

Object literal may only specify known properties, and 'task' does not exist in type 'SetStateAction

在此处输入图片说明 Im building a to-do list with reactJS

and typescript. But i their this error on typescript im begginer with typescript. Somebody can help me?

I don't see any state that use setTasks on your screenshot (please provide some code and not a picture btw), but it's probably because you want to add an object to a state that you initialize with a string. So replacing a string by an object is a non-trivial action that may crash your app elsewhere.

In order to avoid that, just declare a type for your object, and specify the type of the state with it.

 // type object type Task = { id: string; title: string; description: string } // state const [tasks, setTasks] = useState<Task[]>([])

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM