dynamic component not recognized
baojd42 opened this issue · 6 comments
baojd42 commented
IWANABETHATGUY commented
this is expected, because component type is runtime determined, there is no way to infer component props before runtime.
sethidden commented
@IWANABETHATGUY Should theoretically be possible if name
has an explicit type
<template>
<component :is="name" prop-that-only-exists-on-the-somecomponent="hello"/> <!-- should throw error since prop-that-only-exists-on-the-somecomponent cannot be found on OtherComponent -->
<button @click="setSome()">Render Some Component</button>
<button @click="setOther()" >Render Other Component</button>
</template>
<script setup lang="ts">
import SomeComponent from './SomeComponent.vue'
import OtherComponent from './OtherComponent.vue'
const setSome = () => { name.value = SomeComponent }
const setOther = () => { name.value = OtherComponent }
const name = ref<typeof SomeComponent | typeof OtherComponent>(SomeComponent)
</script>
baojd42 commented
@IWANABETHATGUY Thanks for your reply. If <component>
being any is expected, then I can live with that. But it is highlighted the same as a not imported component. That is a bit annoying.
I noticed in the docs, <component>
and <slot>
are both component-like feature of template syntax. Should they be highlighted the same way?
baojd42 commented
@IWANABETHATGUY Should theoretically be possible if
name
has an explicit type<template> <component :is="name" prop-that-only-exists-on-the-somecomponent="hello"/> <!-- should throw error since prop-that-only-exists-on-the-somecomponent cannot be found on OtherComponent --> <button @click="setSome()">Render Some Component</button> <button @click="setOther()" >Render Other Component</button> </template> <script setup lang="ts"> import SomeComponent from './SomeComponent.vue' import OtherComponent from './OtherComponent.vue' const setSome = () => { name.value = SomeComponent } const setOther = () => { name.value = OtherComponent } const name = ref<typeof SomeComponent | typeof OtherComponent>(SomeComponent) </script>
It would be great if this could be implemented.
johnsoncodehk commented
johnsoncodehk commented
Duplicate of #482