【问题标题】:Cannot get func from PropTypes无法从 PropTypes 获取 func
【发布时间】:2018-10-09 00:31:43
【问题描述】:

我无法弄清楚为什么此导入或任何其他方法不起作用:

    import * as React from 'react';
    import TextField from '@material-ui/core/TextField';
    import * as PropTypes from 'prop-types';
    import { withStyles } from '@material-ui/core/styles';
    //import { PropTypes } from '@material-ui/core';

    interface IProps {
        value: string;
        onChange?: PropTypes.func;
    }

    const textField = (props: IProps) => {
        return (
            <div>HI</div>
        );
    };

    export default textField;

我收到的错误是:

ts-app/node_modules/@types/prop-types/index"' 没有导出成员 'func'

我正在查看这个文件,它似乎显然有这样一个成员:

export const func: Requireable<(...args: any[]) => any>;

也许有一天我会了解 React 以及这些依赖项是如何工作的,谢谢!

【问题讨论】:

    标签: reactjs typescript material-ui react-proptypes


    【解决方案1】:

    PropTypes.func 是一个值(用于无状态函数组件的propTypes 属性或组件类的静态属性),但您正试图将其用作类型。相反,您可以手动编写底层类型:

    onChange?: (...args: any[]) => any;
    

    或者希望有更具体的适合您的应用程序。

    filed an issue 为可怜的错误信息。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2016-11-13
      • 1970-01-01
      • 1970-01-01
      • 2018-02-16
      • 1970-01-01
      • 2018-07-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多