【发布时间】:2020-03-19 11:08:28
【问题描述】:
我在描述我的道具类型时遇到了问题。我在以下代码行中遇到错误:
<PostButton handleClick={props.upvote}/>
<PostButton2 handleClick={props.downvote}/>
错误是:
类型'{ handleClick: () => void; 中缺少属性'label' }' 但 '{ handleClick: () => void; 类型中需要标签:字符串; }'.ts(2741) Comments.tsx(62, 55): 'label' 在这里声明。
当我尝试删除 'label: string; ' 从我的函数道具中,它会抛出一个错误说明:
类型'{ handleClick: () => void; 上不存在属性'label' }'。
这是我的代码:
function Button(props: { handleClick: () => void; }) {
let style = {
paddingRight: 100,
};
return (
<div>
<button style={style} onClick={() => props.handleClick()}>
{props.label}
PostButton
</button>
</div>
);
}
【问题讨论】:
标签: reactjs typescript types jsx next.js