Skip to content

create-react-app TypeScript @property decorator not creating accessors correctly #878

@karlbennett

Description

@karlbennett

Description

When using the default TypeScript settings in create-react-app it seems that the @property decorator isn't creating the accessors correctly. Strangle running a delete (delete this.text) on the property fixes the accessors.

Workaround

To get the accessors working for the moment just run a delete on the property you created in the constructor.

@customElement("my-element")
export class MyElement extends LitElement {
    @property() text: string;

    constructor() {
        super();
        delete this["text"]; // This will fix the accessors.
        this.text = "Initial text.";
    }

    render(): TemplateResult {
        return html`<p>${this.text}</p>`;
    }
}

Demo

https://github.com/karlbennett/litelement-property-bug

Steps to Reproduce

Example:

  1. Create my-element
  2. Add a text property to my-element with the @property decorator.
  3. Use the my-element tag in some HTML.
  4. Select the my-element tag instance.
  5. Assign a new value to the text property (myElement.text = 'some new text.';).

Expected Results

A property update should trigger update events/methods (update, updated);

Actual Results

The events/methods are not triggered on a property update.

Browsers Affected

  • Chrome
  • Firefox
  • Edge
  • Safari 11
  • Safari 10
  • IE 11

Versions

  • lit-element: 2.2.1

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions