Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

for-of does not work with DOM collections when target is ES3 or ES5 #2696

Closed
Arnavion opened this issue Apr 9, 2015 · 4 comments
Closed
Labels
By Design Deprecated - use "Working as Intended" or "Design Limitation" instead

Comments

@Arnavion
Copy link
Contributor

Arnavion commented Apr 9, 2015

var paragraphs = document.querySelectorAll("p");
for (let p of paragraphs) {
    console.log(p);
}
foo.ts(2,15): error TS2495: Type 'NodeList' is not an array type or a string type.

Is it because the standard emit will have the wrong behavior for live lists that are modified during iteration? A [].slice.call() in the emit would fix that, but perhaps that detracts from wanting to keep the output as close to the original as possible...

@mhegazy
Copy link
Contributor

mhegazy commented Apr 9, 2015

We did not want to complicate the array emit case, and did not want to do any type-directed emit. So for of only works on arrays for ES3/ES5.

@mhegazy mhegazy added the By Design Deprecated - use "Working as Intended" or "Design Limitation" instead label Apr 9, 2015
@Arnavion
Copy link
Contributor Author

Arnavion commented Apr 9, 2015

Yep, makes sense. Thanks.

@emilgpa
Copy link

emilgpa commented Aug 26, 2015

With core-js should work? I've tried but not work, with babel it works.

@mhegazy
Copy link
Contributor

mhegazy commented Apr 20, 2017

Update on this issue, this should be addressed by #12346 under --downlevelIteration.

@microsoft microsoft locked and limited conversation to collaborators Jun 18, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
By Design Deprecated - use "Working as Intended" or "Design Limitation" instead
Projects
None yet
Development

No branches or pull requests

3 participants