Can I specify the return value type of app.mount()
?
I have a component and I want to create Multiple application instances. However, when I try to use the return value of mount()
to update variables associated with the component, TypeScript shows an error:
Property 'content' does not exist on type 'ComponentPublicInstance<{}, {}, {}, {}, {}, {}, {}, {}, false, ComponentOptionsBase<any, any, any, any, any, any, any, {}>'
Here is my component, which exposes the content:
// myComponent
<template>
hello
</template>
<script lang="ts" setup>
import { ref } from 'vue'
const content = ref('')
defineExpose({ content })
</script>
Mounting the component to the DOM in main.ts
:
// main.ts
import myComponent from './myComponent.vue'
const tooltipInstance = createApp(myComponent).mount('#v-tooltip')
tooltipInstance.content = 'xxx'
At this point, TypeScript throws an error for tooltipInstance.conent
:
Property 'content' does not exist on type 'ComponentPublicInstance<{}, {}, {}, {}, {}, {}, {}, {}, false, ComponentOptionsBase<any, any, any, any, any, any, any, any, any, {}>>'.ts(2339)
Is there a way to determine the component type and apply it to the return value of app.mount()
?