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

Iterator in for ... of loop transpiled to use length property which is undefined #12484

Closed
jasonpang opened this issue Nov 24, 2016 · 2 comments
Labels
Duplicate An existing issue was already created

Comments

@jasonpang
Copy link

TypeScript Version: nightly (2.2.0-dev.20161118)

Chrome Version: Stable 54.0.2840.99 (Official Build) m (64-bit) (Revision 7eca4ce1e662f12cadaf96c30cd2335fd03e7140-refs/branch-heads/2840@{#830})

TypeScript Code: (relevant portion)

for (var param of iterator) {

Transpiled ES5 JavaScript (relevant portion):

 for (... ; _i < iterator_1.length; _i++) {
                 ^^^^^^^^^^^^^^^^^
                 length is undefined

Screenshot of Transpiled ES5 Code:

image

Expected behavior:
Using for (var x of iterator) { ... } should be transpiled correctly.

Actual behavior:
The iterator loop is transpiled to use the length property which appears to be undefined for the iterator.

Reproducible Project

For some reason, GitHub isn't allowing me to upload a .zip file, so here's a Google Drive link to the project ZIP: https://goo.gl/xvbwHu.

@kitsonk
Copy link
Contributor

kitsonk commented Nov 24, 2016

That would have been a compile time error.

Dupe of #11209 and others...

@jasonpang
Copy link
Author

jasonpang commented Nov 25, 2016

Makes sense, I also see this at the bottom here: https://www.typescriptlang.org/docs/handbook/iterators-and-generators.html

Closing since this is a documented issue and there are other open issues about this.

@RyanCavanaugh RyanCavanaugh added the Duplicate An existing issue was already created label Nov 28, 2016
@microsoft microsoft locked and limited conversation to collaborators Jun 19, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Duplicate An existing issue was already created
Projects
None yet
Development

No branches or pull requests

3 participants