Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

static get properties() vs @property(): How to get properties when @property() is used. #1111

Closed
GHNewbiee opened this issue Nov 22, 2020 · 4 comments

Comments

@GHNewbiee
Copy link

GHNewbiee commented Nov 22, 2020

When

  static get properties() {
    return {
      greeting: {type: String},
      data: {attribute: false},
      items: {type: Array},
    };

is used, then

<div>${Object.getOwnPropertyNames(this.constructor.properties).toString()}</div>

does work.

But when

  @property()
  greeting;

  @property({attribute: false})
  data;

  @property({type: Array})
  items;

is used, then TypeError: can't convert undefined to object. I suspect it refers to properties.

So, how can I get the names when @property() is used?

@GHNewbiee GHNewbiee changed the title static get properties() vs @property(): How to get properties when static get properties() vs @property(): How to get properties when @property() is used. Nov 22, 2020
@sorvell
Copy link
Member

sorvell commented Dec 3, 2020

See this example in the other issue you posted: #1102 (comment)

Going to close this as we've added this capability to the next major version, and we're not going to address the issue in the current version given that you can work around the problem as shown above.

@sorvell sorvell closed this as completed Dec 3, 2020
@mscuthbert
Copy link

mscuthbert commented Dec 15, 2023

Hi @sorvell -- this issue is still the top search engine result for iterating properties on a lit-element, and I'm on v3 now, but cannot find out how to list the properties if decorators are used. Can you point to how to do it on new lit versions? Thanks!

Ah! it is static get elementProperties() => Map<string, PropertyDefinition>

@designbyadrian
Copy link

designbyadrian commented May 20, 2024

I've got a class that extends LitElement from Lit 3.1.3, and elementProperties does not exist on the instance.

Edit: it's a static function, so can't access it on the instance.

@justinfagnani
Copy link
Contributor

You can access static properties from the constructor:

this.constructor.elementProperties;

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

5 participants