我有一个按钮组件,我试图使用type
编写道具类型,我在控制台中看到此错误。有人能帮忙吗?
Type '{ children: string; label: string; onClick: () => void; }' is not assignable to type 'IntrinsicAttributes & Props'.
Property 'onClick' does not exist on type 'IntrinsicAttributes & Props'. TS2322
节选自我的代码
type Props = {
label: string;
children: ReactNode;
};
const Button = ({ label, children, ...props }: Props) => (
<button label={label} {...props}>
{children}
</button>
);
您需要将onClick
添加到Props
中,如:
type Props = {
label: string;
children: ReactNode;
onClick: () => void;
};