type of useTemplateRef on generic components only contains exposed functions #5120
Description
Vue - Official extension or vue-tsc version
2.2.0
VSCode version
1.96.2
Vue version
3.5.13
TypeScript version
5.7.3
System Info
No response
package.json dependencies
No response
Steps to reproduce
Hi, I noticed that the type of a template ref created on a generic component is different from normal components. I have a specific usecase where I need to access the underlying component of the template ref using $el
on it. This works as expected for all components except if the component is generic. In this case the type of the template ref will only contain the functions exposed from the component using defineExpose
.
I created a reproduction inside a newly created vue app: https://github.com/markbrockhoff/vue-bug-repros/blob/main/src/App.vue
Steps to reproduce:
- Clone the repo
- Install the dependencies (
pnpm i
) - Run
pnpm type-check
to see the TS error when trying to access$el
on the template ref - Make the component
components/Example.vue
not generic by removinggeneric="T"
from its script tag - Run
pnpm type-check
again and see that the types are now as expected
What is expected?
I'd expect that the type for a template ref created on a generic component behaves the same was as when creating one. It should at least be of type HtmlElement & ExposedFunctions
instead of just ExposedFunctions
.
What is actually happening?
Only the functions exposed from the generic component using defineExpose
are present inside the type of the template ref.
Link to minimal reproduction
https://github.com/markbrockhoff/vue-bug-repros/blob/main/src/App.vue
Any additional comments?
No response