[英]react typescript how to correctly type a SetStateAction
https://codesandbox.io/s/dazzling-gates-ruxzr?file=/src/TodoAdder.tsx https://codesandbox.io/s/dazzling-gates-ruxzr?file=/src/TodoAdder.tsx
so I have a simple todo app and I am tying to type the action that update the state of the todos, I am getting the following error , the error does not happen if I change my Todo type declaration to string instead of o union.所以我有一个简单的 todo 应用程序,我想输入更新 todos 状态的操作,我收到以下错误,如果我将 Todo 类型声明更改为字符串而不是 o union,则不会发生错误。 is this happening because of the union type on my
Todo
interface, I notice that error disappears when i use a String for my status object proprety这是因为我的
Todo
界面上的联合类型而发生的吗?我注意到当我使用字符串作为我的状态对象属性时错误消失了
export type Todo ={
name: String;
id: Number;
status: 'Created' | 'Completed' | 'Archived';
}
只需为payload<\/code>设置一个类型:
const payload: Todo = {
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.