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

ReactjsTypescript

Reactjs Problem Overview


Using typescript and react with TSX files with definitely typed type definitions, I am getting the error:

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

When trying to compile a component with the following 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)

Reactjs Solutions


Solution 1 - Reactjs

The solution was to change the for attribute to 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.

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionMatthew BeattyView Question on Stackoverflow
Solution 1 - ReactjsMatthew BeattyView Answer on Stackoverflow