React's type definition file (@types/react/index.d.ts) only includes standard HTML and React elements and props/attributes.
Consider, for example, that you need to allow the banana prop of type string on the <img> element. In TypeScript+JSX, the <img> element uses the React.ImgHTMLAttributes<T> interface declared in @types/react/index.d.ts as follows:
To allow the custom HTML attribute, add the banana?: string; member to the React.ImgHTMLAttributes<T> interface like this:
This approach makes use of interface merging, a form of TypeScript's declaration merging.
Made by Anton Vasetenkov.
If you want to say hi, you can reach me on LinkedIn or via email. If you like my work, you can support me by buying me a coffee.