Categories
TypeScript Answers

How to fix the “Property does not exist on type ‘DetailedHTMLProps, HTMLDivElement>'” error with React and TypeScript?

Spread the love

To fix the "Property does not exist on type ‘DetailedHTMLProps, HTMLDivElement>’" error with React and TypeScript, we can extend the react module’s types using a declare statement.

For instance, in a .d.ts file, we write

declare module "react" {
  interface HTMLAttributes<T> extends AriaAttributes, DOMAttributes<T> {
    custom?: string;
  }
}

to add the custom property into the HTMLAttributes interface.

Then we can add the custom attribute into the HTML elements in our React project.

By John Au-Yeung

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

Leave a Reply

Your email address will not be published.