171

I have an checkbox TSX(JSX) element:

<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:

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

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

enter image description here

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?

Ben
  • 3,612
  • 3
  • 19
  • 24

4 Answers4

499

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

rossipedia
  • 56,800
  • 10
  • 90
  • 93
40

In order to use React MouseEvent just make sure to add:

import { MouseEvent } from 'react';
Penny Liu
  • 15,447
  • 5
  • 79
  • 98
Guy Engel
  • 2,436
  • 1
  • 17
  • 13
8

You can use SyntheticEvent instead of MouseEvent

Sras
  • 1,686
  • 2
  • 19
  • 29
3

You just need to check if you are importing your event from React.

import { MouseEvent, MouseEventHandler } from 'react';
Wadzio
  • 31
  • 1