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

Import components inside setup #601

Closed
3 tasks done
qcp opened this issue Feb 16, 2023 · 2 comments
Closed
3 tasks done

Import components inside setup #601

qcp opened this issue Feb 16, 2023 · 2 comments
Labels
enhancement New feature or request

Comments

@qcp
Copy link

qcp commented Feb 16, 2023

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

@qcp qcp added the enhancement New feature or request label Feb 16, 2023
@lishaobos
Copy link
Contributor

相同的: #527

我有一个其他的想法:

创建一个 componentInstance.d.ts

import type { GlobalComponents } from '@vue/runtime-core'

declare global {
  type ComponentInstance = {
    [Property in keyof GlobalComponents]: InstanceType<GlobalComponents[Property]>
  }
}

image

@qcp
Copy link
Author

qcp commented Feb 21, 2023

Closed.
Simple and nice solution provided #601 (comment)

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