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

Can't iterate over (U)Int8Array, (U)Int16Array, (U)Int32Array, etc. using for ... of #10005

Closed
SetTrend opened this issue Jul 28, 2016 · 5 comments
Labels
Fixed A PR has been merged for this issue

Comments

@SetTrend
Copy link

This small piece of code doesn't compile:

const bytes = new Uint8Array(8);
window.crypto.getRandomValues(bytes);
for (const byte of bytes) { }

This is the error that's being generated:

C:\Temp>node tsc test.ts
test.ts(5,20): error TS2495: Type 'Uint8Array' is not an array type or a string type.
@andru255
Copy link

andru255 commented Jul 28, 2016

@SetTrend By default Typescript allows types number, boolean, string, any. Please See: https://www.typescriptlang.org/docs/handbook/basic-types.html
But you can create a little bit custom types with interfaces:
https://www.typescriptlang.org/docs/handbook/interfaces.html
I'm in the way to learn more about typescript too

@yortus
Copy link
Contributor

yortus commented Jul 28, 2016

Sounds like you are targeting ES5, for which TypeScript offers limited for..of support. There are related issue about this, like #4947, #6842, #5329, and #3164.

@SetTrend
Copy link
Author

SetTrend commented Jul 28, 2016

Thanks, @yortus, for your enlightening answer.

I believe #3164 gets closest to what I would have imagined for having targetted ES5.

Are there plans to have for ... of get this functionality for ES5, too? I am forced to target IE11 at many corporated places.

@yortus
Copy link
Contributor

yortus commented Jul 29, 2016

@SetTrend I couldn't speak for what the TypeScript team's plans are, but looking at the comments in those linked issues (and also in #4031), there seems to be some sympathy for users but no concrete plans.

@mhegazy
Copy link
Contributor

mhegazy commented Apr 20, 2017

This should be addressed by #12346 under --downlevelIteration. Make sure es2015.iterable is part of your --lib arguments.

@mhegazy mhegazy closed this as completed Apr 20, 2017
@mhegazy mhegazy added the Fixed A PR has been merged for this issue label Apr 20, 2017
@mhegazy mhegazy added this to the TypeScript 2.3 milestone Apr 20, 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

4 participants