为什么复选框事件处理程序中的`MouseEvent`不是通用的?

时间:2021-07-22 03:26:48

I have an checkbox TSX(JSX) element:

我有一个复选框TSX(JSX)元素:

<input type="checkbox" name={i.toString()} onClick={this.handleCheckboxClick} />

With the help of VS code I know that the input parameter type of the this.handleCheckboxClick is MouseEvent<HTMLInputElement>. So I implemented it with:

在VS代码的帮助下,我知道this.handleCheckboxClick的输入参数类型是MouseEvent 。所以我实现了它:

private handleCheckboxClick(event: MouseEvent<HTMLInputElement>) {
    ...
}

Then I get an error saying [ts] Type 'MouseEvent' is not generic. As shown in the image below:

然后我得到一个错误说[ts]类型'MouseEvent'不是通用的。如下图所示:

为什么复选框事件处理程序中的`MouseEvent`不是通用的?

Version of my packages:

我的包的版本:

"@types/react": "^15.0.29",
"@types/react-dom": "^15.5.0",
"react": "^15.6.1",
"react-dom": "^15.6.1",
"typescript": "^2.3.4",

Why is that?

这是为什么?

1 个解决方案

#1


57  

You're probably using the DOM MouseEvent. Try using React.MouseEvent<HTMLInputElement> instead.

您可能正在使用DOM MouseEvent。请尝试使用React.MouseEvent

#1


57  

You're probably using the DOM MouseEvent. Try using React.MouseEvent<HTMLInputElement> instead.

您可能正在使用DOM MouseEvent。请尝试使用React.MouseEvent