How to add custom HTML tag TSX

2.7k Views Asked by At

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

1

There are 1 best solutions below

0
Vasilii P On BEST ANSWER

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;
}