Skip to content

fix(declarations): add rest params to h()#6604

Merged
johnjenkins merged 2 commits intostenciljs:mainfrom
adrianschmidt:fix/h-function-types
Feb 19, 2026
Merged

fix(declarations): add rest params to h()#6604
johnjenkins merged 2 commits intostenciljs:mainfrom
adrianschmidt:fix/h-function-types

Conversation

@adrianschmidt
Copy link
Contributor

What is the current behavior?

The public type definition of h() does not include a rest parameter overload for children, even though the runtime implementation accepts ...children: ChildType[]. This causes type errors when passing multiple children as separate arguments:

// Type error: Expected 1-3 arguments, but got 5.
h('div', { id: 'foo' },
  'bar',
  h('img', { src: 'foo.png' }),
  h('span', null),
);

Additionally, one h() overload (sel, data, children: VNode) was misplaced after the jsx function declarations, separated from the other h() overloads.

GitHub Issue Number: #6181

What is the new behavior?

Add a ...children: (VNode | string | number)[] rest parameter overload to both the h namespace and standalone declarations, matching the runtime implementation. The above example now type-checks correctly.

The misplaced overload is moved back with the other h() overloads.

Documentation

N/A

Does this introduce a breaking change?

  • Yes
  • No

This only adds new overloads — existing code that type-checks today will continue to work.

Testing

This change only affects type declarations. The runtime h() function and its tests (src/runtime/vdom/test/h.spec.ts) are unchanged. The existing tests already exercise rest parameter usage (e.g. h('div', null, 'child 1', 'child 2')), confirming the runtime has always supported this pattern.

Other information

The type definitions in stencil-public-runtime.ts are hand-written and were not derived from the runtime implementation, which is why they drifted apart.

The public type definition of h() does not include a rest parameter
overload for children, even though the runtime implementation accepts
`...children: ChildType[]`. This causes type errors when passing
multiple children as separate arguments, e.g.:

  h('div', null, 'text', h('span', null), h('img', null))

Add an overload accepting `...children: (VNode | string | number)[]`
to both the `h` namespace and the standalone declarations, matching
the runtime behavior.

Also move a misplaced `h(sel, data, children: VNode)` overload that
was separated from the other overloads by the jsx declarations.

fixes: stenciljs#6181
Copilot AI review requested due to automatic review settings February 18, 2026 20:28
@adrianschmidt adrianschmidt requested a review from a team as a code owner February 18, 2026 20:28
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR fixes a type definition mismatch where the public type declarations for the h() function did not include a rest parameter overload for children, even though the runtime implementation has always supported ...children as rest parameters. This caused TypeScript errors when passing multiple children as separate arguments. Additionally, one h() overload was misplaced after the JSX runtime function declarations and has been moved back with the other h() overloads.

Changes:

  • Added ...children: (VNode | string | number)[] rest parameter overload to both the h namespace and standalone function declarations
  • Moved the misplaced h(sel: any, data: VNodeData | null, children: VNode) overload from after the jsxDEV declaration back to the correct location with other h() overloads

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@johnjenkins johnjenkins added this pull request to the merge queue Feb 19, 2026
Merged via the queue into stenciljs:main with commit 4d322a7 Feb 19, 2026
69 checks passed
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.

3 participants