Skip to content

Commit

Permalink
Update composition-api.md Typing Generic Component Template Refs
Browse files Browse the repository at this point in the history
  • Loading branch information
f3oall authored Sep 12, 2023
1 parent 7fe90c5 commit cc65cb5
Showing 1 changed file with 15 additions and 0 deletions.
15 changes: 15 additions & 0 deletions src/guide/typescript/composition-api.md
Original file line number Diff line number Diff line change
Expand Up @@ -397,3 +397,18 @@ import type { ComponentPublicInstance } from 'vue'

const child = ref<ComponentPublicInstance | null>(null)
```

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:

```ts
<script setup lang="ts">
import MyModal from './MyModal.vue'
import type { ComponentExposed } from 'vue-component-type-helpers'

const modal = ref<ComponentExposed<typeof MyModal> | null>(null)

const openModal = () => {
modal.value?.open()
}
</script>
```

0 comments on commit cc65cb5

Please # to comment.