It seems pretty simple but I can't handle this problem I always get same message in console:
Type error: Type '(event: MouseEvent) => void' is not assignable to type '() => Event'. TS2322
This is my code:
//in one class
//some code
render()
return (
<div className={keyStyle} key={key} onClick={() => this.props.turnKey()}></div>
)
//in other classs
//some code
return (
<div className="container">
<Display />
<Keys turnKey={this.activateKey}/>
</div>
);
}
activateKey = (event : React.MouseEvent): void =>{
console.log(event.target);
}
How do I solve this error?
You did not pass event
(which is necessary) to your this.props.turnKey
.
I recommend you to pass this.props.turnKey
as is:
<div className={keyStyle} key={key} onClick={this.props.turnKey}>
Probably, it should solve your problem.
If not, then there is some problem with declaration of the prop this.props.turnKey
. Possibly, you have declared it like this
turnKey: () => Event
instead of
turnKey: (event: React.MouseEvent) => void
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With