Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to add custom HTML tag TSX

Tags:

tsx

custom-tag

While trying to render a custom HTML tag <my-element> in JSX an error displayed Property does not exist on type 'JSX.IntrinsicElements'

I've found some examples of how to do that using

declare global {
  interface IntrinsicElements {
    "my-element": any
  }
}

but this produced another error:

ES2015 module syntax is preferred over custom TypeScript modules and namespaces @typescript-eslint/no-namespace

like image 781
Vasilii P Avatar asked Nov 19 '25 15:11

Vasilii P


1 Answers

I've found the useful link to Typescript guide which helped me a lot:

The main idea is to create a new file with extension d.ts (e.g. myModule.d.ts) which should contain the following

export as namespace JSX;

export interface IntrinsicElements {
  "my-element": any;
}
like image 73
Vasilii P Avatar answered Nov 22 '25 03:11

Vasilii P



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!