Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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:

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)

like image 470
Matthew Beatty Avatar asked Aug 28 '16 03:08

Matthew Beatty


1 Answers

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.

like image 168
Matthew Beatty Avatar answered Nov 08 '22 18:11

Matthew Beatty