ts 小白问个问题

2022-03-02 11:56:16 +08:00
 QGabriel
ts + react + antd

<Form name="basic" labelCol={{span: 8}} wrapperCol={{span: 16}} initialValues={{remember: true}} onFinish={onFinish} onFinishFailed={onFinishFailed} autoComplete="off">
<Form.Item label="用户名" name="username">
<Input />
</Form.Item>
<Form.Item label="密码" name="password">
<Input.Password />
</Form.Item>
<Form.Item wrapperCol={{offset: 8,span: 16,}}>
<Button type="primary" htmlType="submit">登录</Button>
</Form.Item>
</Form>

const onFinishFailed = (errorInfo:any) => {
console.log('Failed:', errorInfo);

/*
errorInfo: {
errorFields: (2) [{…}, {…}]
outOfDate: false
values: {username: undefined, password: undefined}
}
*/
};

问题: 函数 onFinishFailed 的参数 errorInfo 怎么定义泛型? 感觉无从下手 请大佬提供一下思路
1195 次点击
所在节点    TypeScript
3 条回复
duan602728596
2022-03-02 14:05:41 +08:00
import type { ValidateErrorEntity } from 'rc-field-form/es/interface';

const onFinishFailed = (errorInfo: ValidateErrorEntity) => {};
QGabriel
2022-03-02 14:42:53 +08:00
@duan602728596 这个思路是什么?你怎么知道引这个包?
duan602728596
2022-03-02 16:45:41 +08:00
@QGabriel ide 点击 onFinishFailed 会跳转到 npm 包里,会有 onFinishFailed 函数的类型定义,然后再点击 ValidateErrorEntity 会跳转到 rc-field-form/es/interface 里。

这是一个专为移动设备优化的页面(即为了让你能够在 Google 搜索结果里秒开这个页面),如果你希望参与 V2EX 社区的讨论,你可以继续到 V2EX 上打开本讨论主题的完整版本。

https://www.v2ex.com/t/837386

V2EX 是创意工作者们的社区,是一个分享自己正在做的有趣事物、交流想法,可以遇见新朋友甚至新机会的地方。

V2EX is a community of developers, designers and creative people.

© 2021 V2EX