【发布时间】:2019-12-21 22:43:43
【问题描述】:
对于使用 TypeScript 的 React 属性类型的函数类型是否有最佳实践?
我以为这会起作用,但实际上它出错了:
type Props = {
onClick: Function
};
const Submit = ({ onClick }: Props) => {
return (
<button type="button" onClick={onClick}>
click me
</button>
);
在这个线程之后,我得到了它的工作,但它似乎不必要地冗长: https://github.com/Microsoft/TypeScript/issues/20007
type Props = {
onClick: (...args: any[]) => any;
};
const Submit = ({ onClick }: Props) => {
return (
<button type="button" onClick={onClick}>
click me
</button>
);
【问题讨论】:
标签: reactjs typescript