Skip to content

Using ComponentPublicInstance with template refs #2251

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Mar 24, 2023

Conversation

skirtles-code
Copy link
Contributor

#2210 suggested using ComponentPublicInstance instead of InstanceType for template refs:

import { ref, ComponentPublicInstance } from 'vue'
const modal = ref<ComponentPublicInstance<typeof MyModal> | null>(null)

The first generic argument passed to ComponentPublicInstance should be the props, so the usage shown above isn't really correct.

InstanceType may be changed to ComponentInstance in future, see #1543, but currently this isn't available.

However, ComponentPublicInstance can be used as a base type in cases where the exact type of the component isn't available. This will only expose the properties that are common to all component instances, such as $el.

@netlify
Copy link

netlify bot commented Feb 25, 2023

Deploy Preview for vuejs ready!

Name Link
🔨 Latest commit 9769264
🔍 Latest deploy log https://app.netlify.com/sites/vuejs/deploys/640c4925e590b80008fbb50b
😎 Deploy Preview https://deploy-preview-2251--vuejs.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site settings.

@NataliaTepluhina NataliaTepluhina merged commit de6053c into vuejs:main Mar 24, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants