我这样Button
使用antd@3.16.2
:
<Button
type="primary"
loading={true}
onClick={console.log}
block
>
Do something
</Button>
这是我尝试对其进行编译时看到的错误。
Error:(231, 26) TS2740: Type '{ children: string; type: "primary"; loading: boolean; onClick: () => void; block: true; }' is missing the following properties from type 'Pick<Pick<(Readonly<NativeButtonProps> & Readonly<{ children?: ReactNode; }>) | (Readonly<AnchorButtonProps> & Readonly<{ children?: ReactNode; }>), "children" | "style" | ... 257 more ... | "block"> & Pick<...> & Pick<...>, "children" | ... 256 more ... | "shape">': style, title, className, prefixCls, and 251 more.
这是什么意思,我应该在哪里纠正这种类型的不一致?
答案 0 :(得分:1)
this question仅@types/react@16.8.11
就可以解决此问题。
答案 1 :(得分:0)
您不能将console.log放在onClick方法中。 如果需要,可以创建一些功能,在该功能中是控制台日志
例如:
handleClick = (event) => {
console.log(event)
}
,您可以将此函数称为:
<Button
type="primary"
loading={true}
onClick={this.handleClick}
block
>
Do something
</Button>
答案 2 :(得分:0)
I believe this is a duplication of this question. I'll give the same answer as I believe is the same problem.
This issue was fixed by antd 3 days ago. Just update your antd to version 3.16.3 and you will be fine.
Execute: npm i antd@3.16.3 --save
or yarn antd@3.16.3
If you want more details, you can find in this issue