You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
In a parent component, set up unplugin-vue-components and use useTemplateRef:
Working Example (Explicit Import):
<template>
<MyChildref="myChild" />
</template>
<script setup lang="ts">
importMyChildfrom'./MyChild.vue'; // <-- We are using an explicit import here to make it workconst myChild =useTemplateRef('myChild');myChild.value?.sayHello();
</script>
Here, the explicit import ensures that useTemplateRef can infer the sayHello type.
Without the import, type inference breaks, and the following error is displayed:
Property 'sayHello' does not exist on type '{}'. ts-plugin(2339)
Expected Behavior
useTemplateRef should infer the exposed types from MyChild.vue when using unplugin-vue-components, without requiring an explicit import.
Actual Behavior
Type inference fails unless MyChild.vue is explicitly imported, despite unplugin-vue-components resolving the component.
Note
I tried to get a live reproduction going to reproduce the error but StackBlitz doesn't show the TypeScript error for some reason. The link is there none the less.
Describe the bug
When using the new
useTemplateRef
in Vue 3.5+ alongsideunplugin-vue-components
, the exposed types from a component cannot be automatically inferred.Steps to Reproduce
MyChild.vue
component with a sayHello method exposed:unplugin-vue-components
and useuseTemplateRef
:Working Example (Explicit Import):
Here, the explicit import ensures that useTemplateRef can infer the sayHello type.
Failing Example (No Explicit Import):
Without the import, type inference breaks, and the following error is displayed:
Expected Behavior
useTemplateRef
should infer the exposed types fromMyChild.vue
when usingunplugin-vue-components
, without requiring an explicit import.Actual Behavior
Type inference fails unless
MyChild.vue
is explicitly imported, despiteunplugin-vue-components
resolving the component.Note
I tried to get a live reproduction going to reproduce the error but StackBlitz doesn't show the TypeScript error for some reason. The link is there none the less.
Reproduction
https://stackblitz.com/edit/vitejs-vite-2x1yc3tj?file=src%2FApp.vue,src%2Fcomponents%2FMyChild.vue,vite.config.js
System Info
Used Package Manager
pnpm
Validations
The text was updated successfully, but these errors were encountered: