Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions packages-private/dts-test/h.test-d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ describe('h inference w/ element', () => {
h('div', { ref: 'foo' })
h('div', { ref: ref(null) })
h('div', { ref: _el => {} })
h('form', { ref: (_el: HTMLFormElement | null) => {} })
h('div', { ref: (_el: HTMLDivElement | null) => {} })
// @ts-expect-error
h('div', { ref: [] })
// @ts-expect-error
Expand Down
12 changes: 8 additions & 4 deletions packages/runtime-core/src/vnode.ts
Original file line number Diff line number Diff line change
Expand Up @@ -87,10 +87,14 @@ export type VNodeTypes =
export type VNodeRef =
| string
| Ref
| ((
ref: Element | ComponentPublicInstance | null,
refs: Record<string, any>,
) => void)
| {
// Bivariant callback param allows assigning more specific element types,
// e.g. (el: HTMLFormElement | null) => void for <form ref="...">.
Copy link

Copilot AI Mar 31, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Suggested change
// e.g. (el: HTMLFormElement | null) => void for <form ref="...">.
// e.g. (el: HTMLFormElement | null) => void for
// <form :ref="(el: HTMLFormElement | null) => {}">.

Copilot uses AI. Check for mistakes.
bivarianceHack(
ref: Element | ComponentPublicInstance | null,
refs: Record<string, any>,
): void
}['bivarianceHack']

export type VNodeNormalizedRefAtom = {
/**
Expand Down
Loading