Skip to content

Commit cc65cb5

Browse files
authored
Update composition-api.md Typing Generic Component Template Refs
vuejs/language-tools#3206
1 parent 7fe90c5 commit cc65cb5

File tree

1 file changed

+15
-0
lines changed

1 file changed

+15
-0
lines changed

src/guide/typescript/composition-api.md

+15
Original file line numberDiff line numberDiff line change
@@ -397,3 +397,18 @@ import type { ComponentPublicInstance } from 'vue'
397397

398398
const child = ref<ComponentPublicInstance | null>(null)
399399
```
400+
401+
If `MyModal` is a generic component, you should use `ComponentExposed` from the `vue-component-type-helpers` package instead of TypeScript's built-in `InstanceType` utility:
402+
403+
```ts
404+
<script setup lang="ts">
405+
import MyModal from './MyModal.vue'
406+
import type { ComponentExposed } from 'vue-component-type-helpers'
407+
408+
const modal = ref<ComponentExposed<typeof MyModal> | null>(null)
409+
410+
const openModal = () => {
411+
modal.value?.open()
412+
}
413+
</script>
414+
```

0 commit comments

Comments
 (0)