Skip to content

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

Description

@SetTrend

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.

Activity

  1. andru255 commented on Jul 28, 2016

    @andru255

    Axel D. (@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

  2. yortus commented on Jul 28, 2016

    @yortus
    Contributor

    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.

  3. SetTrend commented on Jul 28, 2016

    @SetTrend
    Author

    Thanks, Troy Gerwien (@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.

  4. yortus commented on Jul 29, 2016

    @yortus
    Contributor

    Axel D. (@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.

  5. mhegazy commented on Apr 20, 2017

    @mhegazy
    Contributor

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

  6. locked and limited conversation to collaborators on Jun 19, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    FixedA PR has been merged for this issue

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions