我不明白为什么这个导入或任何其他导入不起作用:
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 以及这些依赖项是如何工作的,谢谢!
最佳答案
PropTypes.func
是一个值(旨在用于无状态函数组件的 propTypes
属性或组件类的静态属性),但您正在尝试将其用作类型。相反,您可以手动编写底层类型:
onChange?: (...args: any[]) => any;
或者希望是更具体的适合您的应用程序。
我filed an issue对于糟糕的错误消息。
关于reactjs - 无法从 PropTypes 获取函数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52711753/