Skip to content

[analyzer] does not infer attributes from TypeScript literal types #298

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

Open
2 tasks done
anhallbe opened this issue Mar 7, 2025 · 0 comments
Open
2 tasks done

Comments

@anhallbe
Copy link

anhallbe commented Mar 7, 2025

Checklist

  • Did you run the analyzer with the --dev flag to get more information?
  • Did you create a minimal reproduction in the playground?

Completing the items above will greatly improve triaging time of your issue.

Expected behavior
Not sure if this is a bug or enhancement request. But the analyzer should pick up attribute values from literal types, in addition to hard-coded strings.

See playground: https://custom-elements-manifest.netlify.app/?source=Y29uc3QgQXR0cmlidXRlcyA9IHsKICAgIFZhcmlhYmxlOiAidmFyaWFibGUiLAp9IGFzIGNvbnN0OwoKCmNsYXNzIE15RWxlbWVudCBleHRlbmRzIEhUTUxFbGVtZW50IHsKICAvLyBPbmx5IHRoZSAic3RyaW5nIiBhdHRyaWJ1dGUgaXMgZGV0ZWN0ZWQKICBzdGF0aWMgZ2V0IG9ic2VydmVkQXR0cmlidXRlcygpIHsKICAgIHJldHVybiBbInN0cmluZyIsIEF0dHJpYnV0ZXMuVmFyaWFibGVdOwogIH0KfQoKY3VzdG9tRWxlbWVudHMuZGVmaW5lKCdteS1lbGVtZW50JywgTXlFbGVtZW50KTsK&library=vanilla

const Attributes = {
    Variable: "variable",
} as const;


class MyElement extends HTMLElement {
  // Only the "string" attribute is detected
  static get observedAttributes() {
    return ["string", Attributes.Variable];
  }
}

customElements.define('my-element', MyElement);

In this example, the type of Attributes.Variable is "variable", so the analyzer should be able to pick that up as an attribute name. But currently it only detects the "string" attribute.

The way this is used in our project is to have a set of "known" attributes that can be used by different components, mixing etc. and to avoid typos and duplicates.

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

1 participant