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

Generated declaration files might have redundant types of template refs #5060

Open
makedopamine opened this issue Dec 17, 2024 · 4 comments
Open
Labels
enhancement New feature or request

Comments

@makedopamine
Copy link

Vue - Official extension or vue-tsc version

2.1.10

VSCode version

Vue version

3.5.13

TypeScript version

5.5.4

System Info

No response

package.json dependencies

No response

Steps to reproduce

Run npx vue-tsc to genereate .d.ts files

What is expected?

If template refs aren't exposed as public, their types should be 'tree-shaken' from generated .d.ts files.

What is actually happening?

The type of barRef is contained in the generated file Foo.vue.d.ts, but actually it or its properties aren't exposed from Foo.vue with slot or defineExpose.

Link to minimal reproduction

https://stackblitz.com/edit/stackblitz-starters-jtpv84

Any additional comments?

No response

@KazariEX
Copy link
Collaborator

KazariEX commented Dec 17, 2024

Tree shake is the responsibility of the bundler, not the transpiler.

@KazariEX
Copy link
Collaborator

I think the output is correct because the refs declared on the template is automatically mounted to the $refs of the component.

@KazariEX KazariEX added invalid This doesn't seem right and removed pending triage labels Dec 18, 2024
@makedopamine
Copy link
Author

The truth is that the transpiler(Typescript Compiler) can tree-shake unused code. If you remove <slot></slot> from the template block in Foo.vue, then re-run npx vue-tsc, you will notice that the helper function __VLS_template is removed from the file Foo.vue.d.ts. I think if we could split __VLS_template into multiple functions, such as __VLS_template_slots and __VLS_template_refs, the generated code would be more tree-shaking-friendly.

@KazariEX
Copy link
Collaborator

I see, but these are two unrelated issues. Anyway,

the refs declared on the template is automatically mounted to the $refs of the component.

@KazariEX KazariEX added enhancement New feature or request and removed invalid This doesn't seem right labels Dec 18, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants