V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
QGabriel
V2EX  ›  TypeScript

ts 小白问个问题

  •  
  •   QGabriel · 2022-03-02 11:56:16 +08:00 · 1182 次点击
    这是一个创建于 783 天前的主题,其中的信息可能已经有所发展或是发生改变。
    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 怎么定义泛型? 感觉无从下手 请大佬提供一下思路
    duan602728596
        1
    duan602728596  
       2022-03-02 14:05:41 +08:00
    import type { ValidateErrorEntity } from 'rc-field-form/es/interface';

    const onFinishFailed = (errorInfo: ValidateErrorEntity) => {};
    QGabriel
        2
    QGabriel  
    OP
       2022-03-02 14:42:53 +08:00
    @duan602728596 这个思路是什么?你怎么知道引这个包?
    duan602728596
        3
    duan602728596  
       2022-03-02 16:45:41 +08:00
    @QGabriel ide 点击 onFinishFailed 会跳转到 npm 包里,会有 onFinishFailed 函数的类型定义,然后再点击 ValidateErrorEntity 会跳转到 rc-field-form/es/interface 里。
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   5390 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 25ms · UTC 08:31 · PVG 16:31 · LAX 01:31 · JFK 04:31
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.