Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/reactjs/25.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Reactjs 错误TS2339:属性';对于';不存在于类型';HTMLProps<;HTMLLabelElement>';_Reactjs_Typescript - Fatal编程技术网

Reactjs 错误TS2339:属性';对于';不存在于类型';HTMLProps<;HTMLLabelElement>';

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

使用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.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
)一样,而不是明确类型定义的问题