Lit 2.0 customElements.define() 抛出 ts(2345)

Lit 2.0 customElements.define() throws ts(2345)

将几个 lit-Components 迁移到 v2 "lit": "2.1.1" 后,我们收到以下打字稿错误:

Argument of type 'typeof MyComponent' is not assignable to parameter of type 'CustomElementConstructor'. Type 'MyComponent' is missing the following properties from type 'HTMLElement': accessKey, accessKeyLabel, autocapitalize, dir, and 275 more.

import { html, css, LitElement } from 'lit';

export default class MyComponent extends LitElement {...}

customElements.define('my-component', MyComponent);

到目前为止代码运行良好 - 这只是 lit 中的一个错误吗?

在使用 typescript 时,您可以使用装饰器版本,而不是调用 define 函数。

import { html, css, LitElement } from 'lit';
import {customElement} from 'lit/decorators.js';

@customElement('my-component')
export default class MyComponent extends LitElement {...}

customElement - Class decorator factory that defines the decorated class as a custom element.