简体   繁体   English

如何添加自定义HTML标签TSX

[英]How to add custom HTML tag TSX

While trying to render a custom HTML tag <my-element> in JSX an error displayed Property does not exist on type 'JSX.IntrinsicElements' 尝试在JSX中呈现自定义HTML标签<my-element> ,显示错误显示'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 ES2015模块语法优于自定义TypeScript模块和名称空间@ typescript-eslint / no-namespace

I've found the useful link to Typescript guide which helped me a lot: 我发现了指向Typescript指南的有用链接,该链接对我有很大帮助:

The main idea is to create a new file with extension d.ts (eg myModule.d.ts) which should contain the following 主要思想是创建一个扩展名为d.ts的新文件(例如myModule.d.ts),其中应包含以下内容

export as namespace JSX;

export interface IntrinsicElements {
  "my-element": any;
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM