How to make Typescript recognize properties created with the "get properties ()" method in Lit-Element?

Viewed 334

When creating a Component with LitElement we can use the @property decorator or the static properties field, as described in the documentation.

I'd like to use this second method with Typescript, but it complains as the field does not exist in the class.

export class MyClass extends LitElement {

  static get properties() { 
    return { 
      greeting: {type: String},
    };
  }

  public constructor() {
    super();
    this.greeting = "test"; // Error: Property 'greeting' does not exist on type 'MyClass'
  }
}

Typescript complains the greeting property does not exist. How can I make Typescript recognize properties created with the "get properties ()" method in Lit-Element?

Why?

I want to be able to avoid repetition by using the spread operator. Something like this:


const obj = {/** Long object definition **/};

export class MyClass extends LitElement {

  static get properties() { 
    return {
      ...obj,
      greeting: {type: String},
    };
  }
}
0 Answers
Related