Skip to content

Return cloneNode as the receiver type#2484

Open
Kelpy2004 wants to merge 1 commit into
microsoft:mainfrom
Kelpy2004:clone-node-receiver-type
Open

Return cloneNode as the receiver type#2484
Kelpy2004 wants to merge 1 commit into
microsoft:mainfrom
Kelpy2004:clone-node-receiver-type

Conversation

@Kelpy2004
Copy link
Copy Markdown

Summary

I updated the DOM override for Node.cloneNode so the generated DOM libs return the receiver type instead of the base Node type. This keeps existing Node behavior as Node, while preserving exact static types for DOM subtypes and custom element subclasses.

Addresses microsoft/TypeScript#283.

Why

cloneNode returns a clone of the node it is called on, but the current declaration forces callers to cast from Node even when the receiver has a more specific static type.

I also checked the prior cloneNode overload history before making this change. This patch uses one receiver-type return on Node rather than adding per-element overloads.

Validation

  • npm run test
  • npx tsc baselines/dom.generated.d.ts <@types/jquery> <@types/tablesorter> --target es2020 --lib es2020 --strict --noEmit --skipLibCheck false --typeRoots <scratch @types>
  • npx tsc baselines/dom.generated.d.ts --lib es5 --noEmit --diagnostics

Diagnostics comparison from this branch:

  • base: symbols 127252, types 59180, instantiations 86295, memory 220514K, check 2.71s, total 4.07s
  • patched: symbols 127573, types 59331, instantiations 86597, memory 223940K, check 2.78s, total 3.86s

@github-actions
Copy link
Copy Markdown
Contributor

Thanks for the PR!

This section of the codebase is owned by @saschanaz - if they write a comment saying "LGTM" then it will be merged.

@Kelpy2004
Copy link
Copy Markdown
Author

@microsoft-github-policy-service agree

@Kelpy2004 Kelpy2004 marked this pull request as ready for review May 17, 2026 06:46
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.

1 participant