Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/typescript/8.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Reactjs 如何在Submit values param type TypeScript上设置react final form_Reactjs_Typescript_Typescript Typings_React Final Form - Fatal编程技术网

Reactjs 如何在Submit values param type TypeScript上设置react final form

Reactjs 如何在Submit values param type TypeScript上设置react final form,reactjs,typescript,typescript-typings,react-final-form,Reactjs,Typescript,Typescript Typings,React Final Form,如何在react final form中设置并更改onSubmit的值类型 inteface IValues { name: string; } <Form onSubmit={(values: IValues) => {}}> // Error happens here // Types of parameters 'values' and 'values' are incompatible. // Type '{}' is missing the f

如何在react final form中设置并更改onSubmit的值类型

inteface IValues {
    name: string;
}
<Form onSubmit={(values: IValues) => {}}>   // Error happens here
//    Types of parameters 'values' and 'values' are incompatible.
//    Type '{}' is missing the following properties from type 'IFormValues': name
interface-IValues{
名称:字符串;
}
{}>//此处发生错误
//参数“值”和“值”的类型不兼容。
//类型“{}”缺少类型“IFormValues”中的以下属性:名称

这可以工作,但我无法获取值。name

<Form onSubmit={(values: object) => {
    // Property 'name' does not exist on type 'object'
    values.name
}}>
{
//类型“object”上不存在属性“name”
values.name
}}>

我可以按如下方式向IValues施放以提取名称

<Form onSubmit={(values: object) => {
    const { name } = values as IValues;
}}>
{
const{name}=值作为值;
}}>
onSubmit来自配置,我试图找到如何设置FormData类型,但找不到。 我可以在jsx中设置FormData吗?
还有其他更好的选项吗?

react final form
支持从版本开始键入值

您可以通过简单地向
表单
组件提供泛型类型来实现它

从'react final form'导入{withTypes}
伊瓦鲁斯界面{
名称:字符串;
}
const{Form}=withTypes()
{}}>

您好,您解决了这个问题吗?还没有。仍然是具体的类型转换由于react final form的类型脚本定义的限制,这目前是不可能的。有一个公共关系可以解决它。