[React Typescript] JSX.IntrinsicElements

发布时间 2023-08-23 14:00:44作者: Zhentiw
        interface IntrinsicElements {
            // HTML
            a: React.DetailedHTMLProps<React.AnchorHTMLAttributes<HTMLAnchorElement>, HTMLAnchorElement>;
            abbr: React.DetailedHTMLProps<React.HTMLAttributes<HTMLElement>, HTMLElement>;
            address: React.DetailedHTMLProps<React.HTMLAttributes<HTMLElement>, HTMLElement>;
            area: React.DetailedHTMLProps<React.AreaHTMLAttributes<HTMLAreaElement>, HTMLAreaElement>;
            article: React.DetailedHTMLProps<React.HTMLAttributes<HTMLElement>, HTMLElement>;
            ...
        }

Basicly it define the HTML component you can use in React, and it's attirubutes;

 

So, if you have a component 

<myNewElement foo="123" />;

You can also add into it:

declare global {
  namespace JSX {
    interface IntrinsicElements {
      myNewElement: {foo: string}
    }
  }
}