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

[expanded-types] Can't pick a type from an interface #106

Open
nikita-rudenko opened this issue Apr 2, 2024 · 2 comments
Open

[expanded-types] Can't pick a type from an interface #106

nikita-rudenko opened this issue Apr 2, 2024 · 2 comments

Comments

@nikita-rudenko
Copy link

Let's say in a file with Lit component I have an interface that describes props:

export interface ButtonProps {
  variant: 'primary' | 'secondary' | 'tertiary'
  size: 'sm' | 'md' | 'lg'
}

Then I reference it for a property:

export class Button extends LitElement {
  @property({ type: String })
  variant: ButtonProps["variant"] = "primary";
 ...

There is no expandedType generated in custom-elements.json. The result looks like this:

...
{
  "kind": "field",
  "name": "variant",
  "type": {
     "text": "ButtonProps[\"variant\"]"
   },
   "default": "\"primary\"",
   "attribute": "variant"
},
...

Expected result:

...
{
  "kind": "field",
  "name": "variant",
  "type": {
     "text": "ButtonProps[\"variant\"]"
   },
   "default": "\"primary\"",
   "attribute": "variant",
   "expandedType": {
     "text": "'primary' | 'secondary' | 'tertiary'"
    }
},
...
@break-stuff
Copy link
Owner

"computed types" like these, generics, and other TS functions are difficult for the analyzer to parse. I haven't found a good way to do that yet.

Out of curiosity if you set it to a new type, does it work?

type ButtonVariants = ButtonProps["variant"];

export class Button extends LitElement {
  @property({ type: String })
  variant: ButtonVariants = "primary";
 ...

@break-stuff
Copy link
Owner

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

No branches or pull requests

2 participants