-
-
Notifications
You must be signed in to change notification settings - Fork 8.5k
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
types(runtime-core): support typed safe vnode ref
on the template
#5387
base: main
Are you sure you want to change the base?
Conversation
✔️ Deploy Preview for vue-next-template-explorer ready! 🔨 Explore the source changes: 119557a 🔍 Inspect the deploy log: https://app.netlify.com/sites/vue-next-template-explorer/deploys/620398f476208d00075a6e80 😎 Browse the preview: https://deploy-preview-5387--vue-next-template-explorer.netlify.app |
✔️ Deploy Preview for vuejs-coverage ready! 🔨 Explore the source changes: 119557a 🔍 Inspect the deploy log: https://app.netlify.com/sites/vuejs-coverage/deploys/620398f4908a2c000802818b 😎 Browse the preview: https://deploy-preview-5387--vuejs-coverage.netlify.app |
✔️ Deploy Preview for vue-sfc-playground ready! 🔨 Explore the source changes: 119557a 🔍 Inspect the deploy log: https://app.netlify.com/sites/vue-sfc-playground/deploys/620398f447206d000810f657 😎 Browse the preview: https://deploy-preview-5387--vue-sfc-playground.netlify.app/ |
Hey @pikax, This is looking good! Is there any risk this might cause type errors in current usage in specific scenarios? In that case we might postpone this to 3.3. If it's fully backwardds-compatible, we an merge it in a patch. I'd assume it is, since people were forced to typecast previously anyways, right? |
The scenarios I can think of are if ppl are declaring wrong const comp = ref<ComponentPublicInstance | undefined>() // the correct type should have `null` too!
const div = ref<HTMLElement>() // this will fail without `| null`
I think most of the cases ppl use the |
# Conflicts: # packages/dts-test/componentRef.test-d.tsx # packages/runtime-core/src/vnode.ts # packages/runtime-dom/src/jsx.ts
Size ReportBundles
Usages
|
Support typesafe
:ref
property when used on the template.This PR adds support when you use
<video :ref="(e)=> e?.playsInline">
or type safe with used withRef
This also brings type safe to custom components and functional components, altho
functional
components will be converted toComponentPublicInstance<Props>
and type safe in that scenario will be a bit trickier for the user.DefineComponent
works out of the box with the expected type being provided, this might cause some problems on some code bases, depending on how the users are declaring theirrefs
, but in most cases it should workDrops the typescript support for TSX
ref={'str'}
Closes #3455