简体   繁体   English

错误TS2339:类型'HTMLProps <HTMLLabelElement>'上不存在属性'for'

[英]error TS2339: Property 'for' does not exist on type 'HTMLProps<HTMLLabelElement>'

Using typescript and react with TSX files with definitely typed type definitions, I am getting the error: 使用typescript并对具有明确类型定义的TSX文件做出反应,我收到错误:

error TS2339: Property 'for' does not exist on type 'HTMLProps<HTMLLabelElement>'.

When trying to compile a component with the following TSX 尝试使用以下TSX编译组件时

<label for={this.props.inputId} className="input-label">{this.props.label}</label>

I have already solved but adding here for the next person since the solution didn't show up anywhere when searching (Google or StackOverflow) 我已经解决了,但在这里为下一个人添加,因为解决方案在搜索时没有出现在任何地方(Google或StackOverflow)

The solution was to change the for attribute to htmlFor 解决方案是将for属性更改for htmlFor

<label htmlFor={this.props.inputId} className="input-label">{this.props.label}</label>

This is a part of the React library itself which apparently handles for differently just like it does class (it uses className ) and not an issue with the definitely typed type definitions. 这是阵营库本身,这显然处理的一部分, for不同就像它class (它使用className ),而不是一个问题与绝对输入类型定义。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 错误TS2339:类型“ TestPage”上不存在属性“ props” - error TS2339: Property 'props' does not exist on type 'TestPage' 错误TS2339:类型“ Readonly &lt;{}&gt;”上不存在属性“ items” - error TS2339: Property 'items' does not exist on type 'Readonly<{}>' 错误 TS2339:“导航器”类型上不存在属性“剪贴板” - error TS2339: Property 'clipboard' does not exist on type 'Navigator' TS2339(TS)属性“状态”在类型上不存在 - TS2339 (TS) Property 'state' does not exist on type 类型 &#39;ModeContextType | 上不存在属性 &#39;menuInfo&#39; 不明确的&#39;。 TS2339 - Property 'menuInfo' does not exist on type 'ModeContextType | undefined'. TS2339 TS2339:“DefaultRootState”类型上不存在属性“tsReducer” - TS2339: Property 'tsReducer' does not exist on type 'DefaultRootState' TS2339:“PropsWithChildren”类型上不存在属性“类” - TS2339: Property 'classes' does not exist on type 'PropsWithChildren “ServerResponse”类型不存在属性“status”(TS2339) - Property 'status' does not exist on type 'ServerResponse' (TS2339) “屏幕”类型上不存在属性“getAllByRole”。 TS2339 - Property 'getAllByRole' does not exist on type 'Screen'. TS2339 EventTarget 类型上不存在属性“值”(ts2339) - Property 'value' does not exist on type EventTarget (ts2339)
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM