I have two globally registered components ParentComponent and ChildComponent. One of the advantages of global registration is that globally registered components are available everywhere in the app. In other words, I don't have to import them in other components to use them. Unfortunately, the same can not be said about types. To access a type from a component I need to import it (checkout ParentComponent code below) whether the component was globally registered or not. Is there a way to export a type from component to "global" scope and have it available anywhere in the app?
main.ts
import { createApp} from 'vue'
import App from './App.vue'
import ParentComponent from './ParentComponent.vue'
import ChildComponent from './ChildComponent.vue'
const app = createApp(App)
app.component('parent-component', ParentComponent)
app.component('child-component', ChildComponent)
app.mount('#app')
ChildComponent (excerpt)
export type ChildComponentEvent = {
message: string
}
export default defineComponent({
methods: {
emitEvent () {
const event: ChildComponentEvent = {
message: 'Hello from child'
}
this.$emit('child-event', event)
}
}
})
ParentComponent (excerpt)
import { ChildComponentEvent } from './ChildComponent'
export default defineComponent({
methods: {
childEventHandler (event: ChildComponentEvent) {
console.log(event)
}
}
})