有html CustomElement的typescript接口吗?

问题描述 投票:0回答:1

我正在尝试在打字稿中实现网络自定义元素。 我发现自定义元素的生命周期回调如下

  • connectedCallback()
  • adoptedCallback()
  • attributeChangedCallback()

这些回调有打字稿接口吗? 我可以使用适当的签名编写这些方法,但我更愿意使用现有的定义。

html typescript custom-element
1个回答
-1
投票

是的,Typescript 有一个名为

 HTMLElementTagNameMap
的接口,它提供了一种通过类型定义来定义和使用自定义元素的方法。

示例:-

interface MyCustomElement extends HTMLElement { .... }

// Register the custom element<br> customElements.define('my-custom-element', MyCustomElement);

© www.soinside.com 2019 - 2024. All rights reserved.