QGabriel

ts 小白问个问题

  •  
  •   QGabriel · Mar 2, 2022 · 1908 views
    This topic created in 1557 days ago, the information mentioned may be changed or developed.
    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  
       Mar 2, 2022
    import type { ValidateErrorEntity } from 'rc-field-form/es/interface';

    const onFinishFailed = (errorInfo: ValidateErrorEntity) => {};
    QGabriel
        2
    QGabriel  
    OP
       Mar 2, 2022
    @duan602728596 这个思路是什么?你怎么知道引这个包?
    duan602728596
        3
    duan602728596  
       Mar 2, 2022
    @QGabriel ide 点击 onFinishFailed 会跳转到 npm 包里,会有 onFinishFailed 函数的类型定义,然后再点击 ValidateErrorEntity 会跳转到 rc-field-form/es/interface 里。
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   1589 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 32ms · UTC 00:00 · PVG 08:00 · LAX 17:00 · JFK 20:00
    ♥ Do have faith in what you're doing.