runem / lit-analyzer

Monorepository for tools that analyze lit-html templates
MIT License
318 stars 36 forks source link

Using enums for properties or attributes #80

Closed Christian24 closed 4 years ago

Christian24 commented 4 years ago

Hello,

I just started testing lit-analyzer and I noticed something with the way we use enums: Think about the following property:

@property({ type: String })
public type: AlertType = AlertType.SUCCESS;

AlertType itself looks like this:

export enum AlertType {
  SUCCESS = 'SUCCESS',
  DANGER = 'DANGER',
  WARNING = 'WARNING',
  INFO = 'INFO',
}

Now it is very easy to use this since I can just go:

<my-component type="${AlertType.SUCCESS}"></mycomponent>

This works great since the enum at runtime just gets transpiled to a String and I do get code completion in my IDE. However, lit-analyzer does not recognize this and fails with Type 'string' is not assignable to 'AlertType'.

ghost commented 4 years ago

Could you try with the property dot syntax instead:

.type="${AlertType.SUCCESS}"

Christian24 commented 4 years ago

I tried that. It leads exactly to the same error.

herberthobregon commented 4 years ago

Is a typescript problem

Update your typescript version

Test:

typescript@3.8.0-dev.20200107

s

@runem this problem should mark it as closed

Christian24 commented 4 years ago

@herberthobregon is right, it was the Typescript version. 3.8 works great.