Skip to content

Import components inside setup #601

Closed
@qcp

Description

@qcp

Clear and concise description of the problem

Quite often there is a need to specify types for a component's ref variable.
To control behavior, such as a toggle, or receive some data.

Simplest example:

MyComponent.vue

<script setup lang="ts">
defineExpose({
  sayHi: () => alert('hi'),
});
</script>

<template>
  <h1>hi</h1>
</template>

App.vue

<script setup lang="ts">
// Now I have to import it manually
// It would be great if auto-import covered this need as well.
import MyComponent from './components/MyComponent.vue';

const myComp = ref<InstanceType<typeof MyComponent>>();
</script>

<template>
  <my-component ref="myComp" />

  <button @click="myComp?.sayHi()">Say Hi</button>
</template>

Current behavior
image

Project with reproduction here

Suggested solution

#562
Closed by author 🤷‍♂️

#527
Seems valid solution

Alternative

No response

Additional context

Related issue
unplugin/unplugin-auto-import#118
But it was closed without solution

Validations

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions