Categories
TypeScript Answers

How to fix the “error TS2339: Property ‘for’ does not exist on type ‘HTMLProps'” error with TypeScript?

Spread the love

Sometimes, we want to fix the "error TS2339: Property ‘for’ does not exist on type ‘HTMLProps’" error with TypeScript.

In this article, we’ll look at how to fix the "error TS2339: Property ‘for’ does not exist on type ‘HTMLProps’" error with TypeScript.

How to fix the "error TS2339: Property ‘for’ does not exist on type ‘HTMLProps’" error with TypeScript?

The "error TS2339: Property ‘for’ does not exist on type ‘HTMLProps’" error with TypeScript, we should replace the for prop with the htmlFor prop.

For instance, we write

const Input = (props) => {
  //...
  return (
    <label htmlFor={props.inputId} className="input-label">
      {props.label}
    </label>
    //...
  );
};

to set the label‘s for attribute by setting the htmlFor prop to a value.

Conclusion

The "error TS2339: Property ‘for’ does not exist on type ‘HTMLProps’" error with TypeScript, we should replace the for prop with the htmlFor prop.

By John Au-Yeung

Web developer specializing in React, Vue, and front end development.

Leave a Reply

Your email address will not be published. Required fields are marked *