Closed kingyue737 closed 2 years ago
From my perspective, you should avoid doing that.
In Vue 2.7 + @vitejs/plugin-vue2
, importing type with the same name of a component in <script setup>
doesn't cause error. Therefore, I think it may be a bug of this plugin. If it is not recommended, the correct way may be importing the value of the component and then get its type, even though this component has been registered globally.
<script setup lang="ts">
import MyComponent from 'path-to-my-component'
const component = ref<InstanceType<typeof MyComponent> | null>(null)
</script>
might help people from Google with a similar issue in Vue 2.6
I ran into a similar naming conflict with variables named after html tags:
<template>
<footer>
<img src="https://something" />
</footer>
</template>
<script setup lang="ts">
const footer = ...
const img = ...
</script>
I had to downgrade unplugin-vue2-script-setup
to v0.7.3.
Describe the bug
Here is an example.
MyComponent
has already been registered globally. If I import the type of this component, the component will be registered locally by plugin, butMyComponent
is actually undefined in this SFC which results into errorCurrent workaround:
Reproduction
https://stackblitz.com/edit/vitejs-vite-hxhqdw
System Info
Used Package Manager
pnpm
Validations