【问题标题】:React typescript for added antdesign (antd) modal not workingReact typescript for added antdesign (antd) modal 不工作
【发布时间】:2020-05-26 01:05:12
【问题描述】:

我试图将我的React typescript 应用程序用于Ant design Modal,但它无法正常工作,任何人都知道如何将帽子具体放在反应打字稿上

我遇到了这个错误

Parameter 'e' implicitly has an 'any' type.  TS7006

    11 |     };
    12 |
  > 13 |     handleOk = e => {
       |                ^
    14 |         console.log(e);
    15 |         this.setState({
    16 |             visible: false,

我的代码在这里

import * as React from 'react';
import { Modal, Button } from 'antd';

class Uni extends React.Component {

    state = { visible: false };

    showModal = () => {
        this.setState({
            visible: true,
        });
    };

    handleOk = e => {
        console.log(e);
        this.setState({
            visible: false,
        });
    };

    handleCancel = e => {
        console.log(e);
        this.setState({
            visible: false,
        });
    };

    public render () {
        return(
            <div>
                <Button type="primary" onClick={this.showModal}>
                    Open Modal
                </Button>
                <Modal
                    title="Basic Modal"
                    visible={this.state.visible}
                    onOk={this.handleOk}
                    onCancel={this.handleCancel}
                >
                    <p>Some contents...</p>
                    <p>Some contents...</p>
                    <p>Some contents...</p>
                </Modal>
            </div>
        )
    }
}
export default Uni;

【问题讨论】:

    标签: reactjs typescript antd ant-design-pro


    【解决方案1】:

    解决方法就是给它一个类型,在 TypeScript 中你不能有任何隐式类型。

    HandleOK = (e: any) => { ... }

    你可以查找类似事件的打字稿类型,而不是任何类型,我不确定我头顶上的正确类型是什么

    【讨论】:

    • 感谢您的时间和回答,它对我有用:)
    • 我建议你提供实际的types 而不是any
    • 是的,这就是为什么我说他可以调查事件的类型,但问题是关于如何解决问题,任何问题都可以。事件的类型一开始可能有点棘手,所以从 any 开始让应用程序完全运行是一个很好的起点 imho
    猜你喜欢
    • 1970-01-01
    • 2019-01-17
    • 2018-09-16
    • 2022-11-22
    • 1970-01-01
    • 1970-01-01
    • 2022-01-21
    • 2019-01-26
    • 2020-09-26
    相关资源
    最近更新 更多