lwc icon indicating copy to clipboard operation
lwc copied to clipboard

Decorated static props are treated as instance props

Open wjhsf opened this issue 11 months ago • 0 comments

Description

Using @api on a static property will result in the property being parsed as an instance prop. @api static foo is treated as if it were the same as @api foo, although any initial values are preserved on the static prop.

Steps to Reproduce

Child component:

export default class Child extends LightningElement {
  @api static foo = 'hello'
  get staticFoo() {
    // expose static prop via the instance
    return Child.foo
  }
}
<template>
<div>{staticFoo} {foo}</div>
</template>

Parent component:

<template>
<x-child foo="world"></x-child>
</template>

Expected Results

Using @api, @wire, or @track on a static property should be a compiler error, because the decorators only make sense to use on component instances.

Actual Results

The example above will render <div>hello world</div>. @wire and @track behave similarly.

wjhsf avatar Jan 22 '25 19:01 wjhsf