React JS FormControl 事件的类型安全 onChange

Leo*_*all 0 types typescript reactjs

我有一个处理不断变化的文本字段的函数:

private handleNameChange(e: React.FormEvent<FormControl>) {
    const name = e.target.value;
    this.setState({ name });
    this.props.editGroupName(name);
}
Run Code Online (Sandbox Code Playgroud)

这连接到 FormControl 的 onChange:

<FormControl type='text' placeholder='Name' value={this.state.name} onChange={this.handleNameChange} />
Run Code Online (Sandbox Code Playgroud)

然而,根据 TypeScript 的说法,这是错误的:

TS2339: Property 'value' does not exist on type 'EventTarget'.
Run Code Online (Sandbox Code Playgroud)

我也尝试过使用currentTarget. 我怎么解决这个问题?

小智 5

尝试替换e: React.FormEvent<FormControl>e: React.FormEvent<FormControlProps>.