Skip to content

Conversation

@Uday-Choudhary
Copy link

@Uday-Choudhary Uday-Choudhary commented Nov 22, 2025

fix(types): add[Symbol.iterator]() to NodeListOf

This PR adds missing iterable support to NodeListOf<TNode> in the DOM
typings. Without this method, TypeScript raises error TS2488:

for (const child of div.childNodes) {}
// TS2488: NodeListOf<ChildNode> must have a [Symbol.iterator]() method

This brings Deno’s DOM types in line with upstream lib.dom.d.ts, where
NodeListOf is defined as iterable.

Related Issue

Fixes #31382

Details

The following method was added to NodeListOf<TNode>:

[Symbol.iterator](): IterableIterator<TNode>;

This is a type-only change and does not affect the runtime behavior of Deno.
The fix allows idiomatic iteration over NodeListOf, such as:

for (const child of element.childNodes) {
  console.log(child);
}

@CLAassistant
Copy link

CLAassistant commented Nov 22, 2025

CLA assistant check
All committers have signed the CLA.

@coderabbitai
Copy link

coderabbitai bot commented Nov 22, 2025

Walkthrough

Adds [Symbol.iterator](): IterableIterator<TNode>; to the NodeListOf<TNode extends Node> declaration in the DOM typings and adds a test tests/tsc/dom_nodelistof_iterable.ts that creates a div with two <p> children and iterates over div.childNodes with for...of, accessing each child’s nodeName.

Sequence Diagram(s)

sequenceDiagram
  autonumber
  participant Test as Test (tsc test)
  participant DOM as DOM (runtime)
  participant Types as lib.dom.d.ts

  Note over Types: Declaration change — NodeListOf has [Symbol.iterator]()
  Test->>DOM: document.createElement("div")
  Test->>DOM: div.innerHTML = "<p>a</p><p>b</p>"
  Test->>DOM: for (const node of div.childNodes) { ... }
  activate DOM
  DOM->>DOM: div.childNodes (NodeListOf)
  Note over DOM,Types `#dff0d8`: iteration uses\n[Symbol.iterator]() declared on NodeListOf
  DOM-->>Test: yields Node (p, p) via iterator
  deactivate DOM
Loading

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

  • Files to inspect:
    • cli/tsc/dts/lib.dom.d.ts — verify correct placement and signature of [Symbol.iterator]() and compatibility with other collection typings.
    • tests/tsc/dom_nodelistof_iterable.ts — confirm test correctness and that iteration behaves as intended.

Pre-merge checks and finishing touches

✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title accurately and clearly describes the main change: adding Symbol.iterator to NodeListOf with a reference to the fixed issue.
Linked Issues check ✅ Passed The PR fully addresses issue #31382 by adding the missing Symbol.iterator method to NodeListOf, resolving the TS2488 error.
Out of Scope Changes check ✅ Passed All changes are in scope: the iterator method added to NodeListOf and a test file validating the fix. No unrelated modifications present.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Description check ✅ Passed The pull request description accurately describes the changeset, explaining the addition of Symbol.iterator to NodeListOf and the TypeScript error it fixes.
✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment

Comment @coderabbitai help to get the list of available commands and usage tips.

@Uday-Choudhary Uday-Choudhary force-pushed the fix-nodelistof-iterator branch from a7bbe2b to d05388f Compare November 22, 2025 21:17
@Uday-Choudhary
Copy link
Author

Kindly requesting a review when convenient.

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.

dom types: NodeListOf type doesn't have Symbol.iterator

2 participants