fix(runtime-core): relax function ref callback variance#14658
fix(runtime-core): relax function ref callback variance#14658Misrilal-Sah wants to merge 1 commit intovuejs:mainfrom
Conversation
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (2)
📝 WalkthroughWalkthroughThe changes update Vue's ref callback typing system by refactoring Changes
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes Poem
🚥 Pre-merge checks | ✅ 3✅ Passed checks (3 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Pull request overview
This PR updates Vue’s runtime-core TypeScript typings for function refs so ref callbacks can use narrower DOM element parameter types (e.g. HTMLFormElement for <form> refs), addressing #13969.
Changes:
- Made
VNodeReffunction-ref callbacks bivariant to relax parameter variance for element-specific callback typing. - Added DTS regression coverage ensuring
h('form' | 'div', { ref: (el: HTMLFormElement/HTMLDivElement | null) => {} })type-checks.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
| packages/runtime-core/src/vnode.ts | Updates VNodeRef callback typing to be bivariant so narrower element parameter types are accepted. |
| packages-private/dts-test/h.test-d.ts | Adds DTS regression cases for HTMLFormElement / HTMLDivElement function refs. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| ) => void) | ||
| | { | ||
| // Bivariant callback param allows assigning more specific element types, | ||
| // e.g. (el: HTMLFormElement | null) => void for <form ref="...">. |
There was a problem hiding this comment.
The example in the new comment is slightly misleading for function refs: <form ref="..."> reads like a string ref. Consider changing it to something like <form :ref="(el: HTMLFormElement | null) => {}"> (or otherwise clarify it’s a function ref) so the comment matches the feature being typed here.
| // e.g. (el: HTMLFormElement | null) => void for <form ref="...">. | |
| // e.g. (el: HTMLFormElement | null) => void for | |
| // <form :ref="(el: HTMLFormElement | null) => {}">. |
|
duplicate of #14529 |
Issue link
#13969
Description
This PR adjusts function-ref typing so callbacks with narrower HTMLElement parameter types are accepted (for example HTMLFormElement on form refs).
Why
Template/function refs should allow element-specific callback parameter typing, but current type variance rejected valid narrower element types.
Changes
Updated VNode function ref callback typing to be bivariant.
Added dts regression cases for HTMLFormElement/HTMLDivElement function refs.
Summary by CodeRabbit