首页 > 解决方案 > 将 TS 定义添加到 WebComponents

问题描述

@abc/ui-webcomponents导出一堆建立在(plain js)之上的WebComponents LitElement,如下所示:

export class AbcButton extends LitElement {
  static get properties() {
    return {
      foo: {
        type: Boolean
      },
      bar: {
        type: String
      }
    };
  }
  render() {
    return html`...`;
  }
}

window.customElements.define('abc-button', AbcButton);

由于主要用于 Angular 项目,因此拥有描述属性的定义@abc/ui-webcomponents会很有帮助。.d.ts

我一直在尝试以下方法,但没有成功:

interface HTMLElementTagNameMap {
  'abc-button': NgElement & WithProperties<{foo: string, bar: string}>;
  // or
  'abc-button': AbcButton;
}

至少 在. <abc-_ <abc-button f_app.component.html

标签: angulartypescriptweb-componentlit-element

解决方案


推荐阅读