microsoft / fast

The adaptive interface system for modern web experiences.
https://www.fast.design
Other
9.28k stars 595 forks source link

fix: Implicit underscore-prefixed observable properties in fast-element #6824

Open albertor24 opened 1 year ago

albertor24 commented 1 year ago

🐛 Bug Report

When creating an @observable property, an implicit property with the same name prefixed with underscore will be created. Moreover, if an explicit underscore-prefixed property is declared alongside a non-prefixed property, they will overwrite each other

💻 Repro or Code Sample

https://stackblitz.com/edit/typescript-j2eqbm?file=index.ts

const template = html`
  <h1>${x => x.myProp}</h1>
`;

class MyElement extends FASTElement {
  @observable myProp = "Just my prop";
  private _myProp = "My prop with underscore";
}

🤔 Expected Behavior

The template should show Just my prop

😯 Current Behavior

The template shows My prop with underscore

💁 Possible Solution

If it's necessary to create these implicit properties, an error should be raised if a property with underscore is explicitly defined.

🔦 Context

🌍 Your Environment

janechu commented 5 months ago

~I don't think we want to add overhead to runtime checking, so I'm marking this as a documentation issue, we should explicitly state that we are creating private underscore properties and that they should not be overwritten.~

After some discussion with maintainers it seems that a potential solution is to use Symbol this may however have perf implications.