open-wc / custom-elements-manifest

Custom Elements Manifest is a file format that describes custom elements in your project.
https://custom-elements-manifest.open-wc.org/
226 stars 37 forks source link

Type annotations on a (lit) property are ignored if the property has a default value #234

Closed rstoneIDBS closed 4 months ago

rstoneIDBS commented 4 months ago

Checklist

Playground Reproduction

Expected behavior In the playground example, I would expect the type for the foo property to be:

"type": {
  "text": "'one' | 'two'"
}

I did experiment with trying to force the type of the default value via JSDoc comments but this didn't change the output

rstoneIDBS commented 4 months ago

And then I tried again :)

Adding:

  constructor() {
    super();
    /** @type {'one' | 'two'} */   
    this.foo = 'hello';
  }

gets it working, however I wonder if this is still an issue, i.e. having the types declared with the properties feels much nicer than having to spread them around into constructors too

thepassle commented 4 months ago

Yeah, that wont work; for TS that won't work either, because TS is not aware that the properties defined in static properties will get turned into actual class properties by lit internally. You could write a custom plugin to support this, but I doubt we'll support this in core

rstoneIDBS commented 4 months ago

Yup - just bumped into the TS thing not working too :( TS aside, when you say it "won't work" - why does it work for the 'bar' property that doesn't have a default value?

I'm going to guess that its because 'lit' mode knows to look in the static properties, but also gets overridden when the generic CEM code finds a 'standard' property via the default value?