how to define the return value type of app.mount() #7493
Answered
by
chenxch
Mr-Nobody-li
asked this question in
Help/Questions
-
how to define the return value type of
here is my component, and expose content // myComponent
<template>
hello
</template>
<script lang="ts" setup>
import { ref } from 'vue'
const content = ref('')
defineExpose({ content })
</script> mount component to dom in // main.ts
import myComponent from './myComponent.vue'
const tooltipInstance = createApp(myComponent).mount('#v-tooltip')
tooltipInstance.content = 'xxx' At this time, ts reports an error for
Is there any way to get the type of component and apply it to the return value of |
Beta Was this translation helpful? Give feedback.
Answered by
chenxch
Jan 15, 2023
Replies: 1 comment 2 replies
-
This solution should solve your problem. import myComponent from './myComponent.vue'
import type { ComponentPublicInstance } from 'vue'
import type MyComponent from './myComponent.vue'
type MyComponentInstance = InstanceType<typeof MyComponent>
const tooltipInstance = createApp(myComponent).mount('#v-tooltip') as ComponentPublicInstance<MyComponentInstance>
tooltipInstance.content = 'xxx' |
Beta Was this translation helpful? Give feedback.
2 replies
Answer selected by
Mr-Nobody-li
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This solution should solve your problem.