Eckher
EckherInsightsContact
Eckher
Your guide to what's next.
Declaring custom JSX/HTML attributes in TypeScript
Apr 4, 2020

Declaring custom JSX/HTML attributes in TypeScript

How to specify non-standard JSX/HTML attributes in TypeScript?

Those who switched to TypeScript may experience problems with non-standard JSX/HTML props/attributes. React's type definition file () only includes standard HTML and React elements and props/attributes.

Consider, for example, that you need to allow the prop of type on the element. In TypeScript+JSX, the element uses the interface declared in as follows:

To allow the custom HTML attribute, add the member to the interface:

This approach makes use of interface merging, a form of TypeScript's declaration merging.

See also
Built-in React hooks
The list of built-in React hooks.
Multi-<select> in React
How to implement a controlled multi-<select> in React?
How to run a JSX script?
Executing .jsx files with command line.
<select> in React
How to implement a controlled <select> in React?