definitelytyped.github.io icon indicating copy to clipboard operation
definitelytyped.github.io copied to clipboard

Typed React event handler

Open ccorcos opened this issue 9 years ago • 1 comments

Seems to me like this should work:

class MouseDown extends React.Component<{}, {}> {
	onMouseDown = (event: MouseEvent) => {
		console.log(event)
	}
	render() {
		return <div onMouseDown={this.onMouseDown} />
	}
}

Ideally I could just leave off the type signature and it would be inferred based on how we're calling it, but that doesnt work. So I don't know how to get this to compile.

ccorcos avatar Mar 27 '17 23:03 ccorcos

Did no one figure this out yet or nobody wants to share ? :)

import React, { MouseEvent } from 'react'

onMouseDown = (event: MouseEvent<HTMLDivElement>) => {
}

danielkcz avatar Feb 05 '18 11:02 danielkcz