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
custom elements manifest analyzer creates wrong types when using an interface #193
Comments
Hi, I'm facing the same problem with the type assignment in lit element classes. Here a minimal reproduction to see the problem in action: https://stackblitz.com/edit/vitejs-vite-d2fdrz?file=src/my-element.ts Looks like CEM cannot get the type reference correctly when collecting the manifest data. This is the module.exports = {
/** Globs to analyze */
globs: ['src/**/*.ts'],
/** Directory to output CEM to */
outdir: '.',
/** Output CEM path to `package.json`, defaults to true */
packagejson: false,
/** Enable special handling for litelement */
litelement: true,
}; Ideally the following code: export type Counter = number;
export type MyElementProps = {
count: Counter;
docsHint: string;
};
/**
* An example element.
*
* @slot - This element has a slot
* @csspart button - The button
*/
@customElement('my-element')
export class MyElement extends LitElement {
/**
* Copy for the read the docs hint.
*/
@property()
docsHint: MyElementProps['docsHint'] =
'Click on the Vite and Lit logos to learn more';
/**
* The number of times the button has been clicked.
*/
@property({ type: Number })
count: MyElementProps['count'] = 0; Should produce this:
Thanks a lot |
The analyzer doesnt use typescripts typechecker because it makes analysis super slow. This means that it gives you the types in the manifest as is typed in the source code. You can override this behavior by using the |
Thanks for the quick response @thepassle. |
These are the docs I mentioned: https://custom-elements-manifest.open-wc.org/analyzer/plugins/authoring/#overriding-sourcefile-creation |
Checklist
--dev
flag to get more information?Expected behavior
We are using the custom elements manifest analyzer to create a custom-elements.json that we can use in our storybook docs.
We use lit with typescript decorators and types via an interface.
When we run our command it creates the types wrong:
But it should create it like this:
Our interface:
Our WebComponent:
Our command:
cem analyze --litelement --outdir "dist"
Is there a setting or config we can use, so that the types get correctly inferred from the interface?
If it is a bug, will this be fixed soon?
Thanks!
The text was updated successfully, but these errors were encountered: