I receive this error
Error:(17, 35) TS2339: Property 'checked' does not exist on type 'EventTarget & Element'.
But that's definitely impossible error because React docs says checked
does exist on target
of checkbox (https://reactjs.org/docs/forms.html#handling-multiple-inputs)
Here is my code. What's wrong with it so TS blows up?
// I specify a type for event. It must have `checked` property.
onToggle = (ev: React.ChangeEvent) => {
console.log('[ev]', ev.target.checked); // <= TS throws here
}
render() {
return (
<div>
<input type="checkbox" name="switch" id="switch" onChange={ev => this.onToggle(ev)} checked={this.state.on}/>
</div>
)
}
Alternative error message:
TS2339: Property 'checked' does not exist on type 'EventTarget'.