Skip to content

for-of does not work with some DOM collections when target is ES6 #2695

Closed
@Arnavion

Description

@Arnavion

Update: This issue is now only for the following collections:

  • MediaList
  • StyleSheetList
  • CSSRuleList

Originally it was about NodeList as well, but that was fixed (along with DOMTokenList) in #3393


Original:

var paragraphs = document.querySelectorAll("p");
for (let p of paragraphs) {
    console.log(p);
}
foo.ts(2,15): error TS2488: The right-hand side of a 'for...of' statement must have a '[Symbol.iterator]()' method that returns an iterator.

Seems it just needs an update to lib.es6.d.ts to add the [Symbol.iterator()] to all the collections that have an indexer and length property. The ones I found that have it in Nightly are below. The rest were either IE-only or didn't exist. Removed my list since it seems FF has more than the specs allow. See zloirock/core-js#137 (comment) for a more accurate list.

Metadata

Metadata

Assignees

No one assigned

    Labels

    BugA bug in TypeScriptDomain: lib.d.tsThe issue relates to the different libraries shipped with TypeScriptHelp WantedYou can do this

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions