【发布时间】:2019-07-14 20:13:11
【问题描述】:
我收到此错误
错误:(17, 35) TS2339:“EventTarget & Element”类型上不存在“已检查”属性。
但这绝对是不可能的错误,因为 React 文档说 checked 确实存在于复选框的 target 上 (https://reactjs.org/docs/forms.html#handling-multiple-inputs)
这是我的代码。怎么回事,TS炸了?
// 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>
)
}
其他错误消息:
TS2339:“EventTarget”类型上不存在“已检查”属性。
【问题讨论】:
标签: reactjs typescript