Reactjs 错误TS2339:属性';对于';不存在于类型';HTMLProps<;HTMLLabelElement>';
使用typescript并使用带有明确类型定义的TSX文件进行响应,我得到了错误:Reactjs 错误TS2339:属性';对于';不存在于类型';HTMLProps<;HTMLLabelElement>';,reactjs,typescript,Reactjs,Typescript,使用typescript并使用带有明确类型定义的TSX文件进行响应,我得到了错误: error TS2339: Property 'for' does not exist on type 'HTMLProps<HTMLLabelElement>'. 错误TS2339:类型“HTMLProps”上不存在属性“for”。 尝试使用以下TSX编译组件时 <label for={this.props.inputId} className="input-label">{this
error TS2339: Property 'for' does not exist on type 'HTMLProps<HTMLLabelElement>'.
错误TS2339:类型“HTMLProps”上不存在属性“for”。
尝试使用以下TSX编译组件时
<label for={this.props.inputId} className="input-label">{this.props.label}</label>
{this.props.label}
我已经解决了,但在这里为下一个人添加,因为在搜索(Google或StackOverflow)时,解决方案没有显示在任何地方。解决方案是将
for
属性更改为htmlFor
<label htmlFor={this.props.inputId} className="input-label">{this.props.label}</label>
{this.props.label}
这是React库本身的一部分,它显然以不同的方式处理for
,就像它处理class
(它使用className
)一样,而不是明确类型定义的问题