-
Notifications
You must be signed in to change notification settings - Fork 13k
Closed
Labels
FixedA PR has been merged for this issueA PR has been merged for this issueSuggestionAn idea for TypeScriptAn idea for TypeScript
Milestone
Description
NodeList
interface is defined as iterable in DOM4, but by design it cannot be directly used in for-of loop because we cannot declare it as iterable in ES5.
Suggestion
Introduce a ES5-compatible way to declare iterable interfaces (Similar to what discussed in #2862)
// WebIDL-like way
interface NodeList {
iterable<Node>
}
// extends-like way
interface NodeList iterable<Node> {}
iterable<T>
in ES6 mode will work as a shorthand of [Symbol.iterator](): IterableIterator<T>
but in ES5 mode will just make an internal flag to be allowed in for-of loop.
// NodeList is marked as iterable,
// it has .length property and index signature for ES5 emit, so all good
for (let node of document.querySelectorAll("...")) {
}
This will make it work both on ES5 and ES6 without changing emit.
michalstocki, alex-kinokon, 0815fox, owendismuke, asgarli and 6 more
Metadata
Metadata
Assignees
Labels
FixedA PR has been merged for this issueA PR has been merged for this issueSuggestionAn idea for TypeScriptAn idea for TypeScript