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 iterator fail with FormData.entries() #13515

Closed
KhaledElAnsari opened this issue Jan 16, 2017 · 11 comments
Closed

for...of iterator fail with FormData.entries() #13515

KhaledElAnsari opened this issue Jan 16, 2017 · 11 comments
Labels
Fixed A PR has been merged for this issue

Comments

@KhaledElAnsari
Copy link

KhaledElAnsari commented Jan 16, 2017

Hello,

I was trying to iterate through the FormData values with the .entries() function using for...of iterator and it failed! I tried to do the same thing with other transpiler and it worked!

TypeScript Version: 2.0.10
Browser Used: Chrome 55.0.2883.87, FireFox 50.1.0
Code

// same simple MDN example
let formData = new FormData();
formData.append('key1', 'value1');
formData.append('key2', 'value2');
for(let pair of formData.entries()) {
   console.log(pair[0] + ": ", pair[1]); 
}

Expected behavior:

Nothing was printed in the console

Actual behavior:

key1: value1
key2: value2
@KhaledElAnsari KhaledElAnsari changed the title for ..of iterator fail with FormData.entries() for...of iterator fail with FormData.entries() Jan 16, 2017
@hzoo
Copy link

hzoo commented Jan 16, 2017

I didn't mean that this needed to be a new issue, in #3164 (comment)

I think @mhegazy already explained why TypeScript isn't supporting it unless you are compiling to ES6, otherwise you can use TS -> Babel

@KhaledElAnsari
Copy link
Author

@hzoo did't see that :\ but it explains a lot! thanks

@aluanhaddad
Copy link
Contributor

This is no longer the case. #12346

@hzoo
Copy link

hzoo commented Jan 16, 2017

Oh right 👍 forgot about that.

@arciisine
Copy link

I'm experiencing the same behavior, running in node 7. My work around was to wrap the .entries() call with Array.from(...). I'm inclined to believe it's a Node issue.

@aluanhaddad
Copy link
Contributor

@arciisine This feature has not yet landed for --target < es2015
Since you are on Node 7. You can use --target >= es2015 and it will just work.

@arciisine
Copy link

arciisine commented Jan 17, 2017

I am using the target es2015 and I had the same issue that the loop was not iterating. I had to add Array.from to get the loop to iterate properly.

Edit: Running basic tests, Map.entries() is fine with target es2015. I definitely hit this issue before (with target es2015) but I have also hit some other odd edge cases, so it may be something to do with my setup.

@blakeembrey
Copy link
Contributor

@arciisine What's the error you're getting? There's no FormData object natively in node.

@arciisine
Copy link

arciisine commented Jan 17, 2017

The error was wrt to iterating on map.entries(), and the iteration being skipped unless I wrapped map.entries() in Array.from(...). I'm assuming it is something to do with the Iterator construct vs having an array. That is to mean, nothing specific with FormData but Map.

@ollwenjones
Copy link

Just ran across this issue with Map.entries() (and .values() and .keys()) Why doesn't TS follow the spec? Or is MDN wrong about the for...of loop working on Map?
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Map

@mhegazy
Copy link
Contributor

mhegazy commented Apr 19, 2017

Should be fixed by #14859 in TS 2.3.

if you are using --lib option in your tsconfig.json make sure you add dom.iterable

@mhegazy mhegazy closed this as completed Apr 19, 2017
@mhegazy mhegazy added the Fixed A PR has been merged for this issue label Apr 19, 2017
@mhegazy mhegazy added this to the TypeScript 2.3.1 milestone Apr 19, 2017
@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
Fixed A PR has been merged for this issue
Projects
None yet
Development

No branches or pull requests

7 participants