0

After migrating several lit-Components to v2 "lit": "2.1.1", we receive the following typescript error:

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);

Code runs fine so far - is this just a bug in lit?

StephanB
  • 315
  • 2
  • 17
  • 1
    Does this also happen, when you use the decorators? `@customElement('my-component')`. Would be easier anyways and if you are using typescript already... And which ts version are you using? – Christian Jan 12 '22 at 21:33
  • Hey, thanks for your input! Error message is gone =) I am using typescript version 4.5.4 – StephanB Jan 13 '22 at 07:24
  • 1
    Cool, than I post that as answer. Please accept. – Christian Jan 13 '22 at 07:28

1 Answers1

1

Instead of calling the define function, you can use the decorator version when using typescript.

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.

Christian
  • 3,503
  • 1
  • 26
  • 47