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

Symbol.interator for array of numbers? #11102

Closed
sant123 opened this issue Sep 23, 2016 · 11 comments
Closed

Symbol.interator for array of numbers? #11102

sant123 opened this issue Sep 23, 2016 · 11 comments
Labels
Docs The issue relates to how you learn TypeScript

Comments

@sant123
Copy link

sant123 commented Sep 23, 2016

TypeScript Version: Playground.

Hi, in the playground version I found this:

image

Code

function myFunc() {
    let items = [1, 2, 3, 4, 5];

    for (let item of items) {
        console.log(item);
    }
}

Expected behavior:
No error.

Actual behavior:
An error.

In normal JS this is not an error:

image

@kitsonk
Copy link
Contributor

kitsonk commented Sep 23, 2016

That seems to be a really odd configuration of Playground that is causing it with the release of TypeScript 2.0. It seems like the Playground is sort of stuck between ES5 and ES6. The emit is ES5, but the syntax checking is ES6 but without the proper libraries loaded.

Running locally, both targeting ES5 and ES6 that works without issue.

@sccolbert
Copy link

Another example:

capture

@sant123
Copy link
Author

sant123 commented Sep 23, 2016

That's right @kitsonk, but only occurs in the playground. Also async and generator statements are "compiled" with no problems, but the result code is not compatible with ES5 and below. I've tested it with VS Code too but I do not get problems.

@sccolbert
Copy link

I get this error when running the code above targeting ES5 output. i.e. not limited to playground for me:
error TS2346: Supplied parameters do not match any signature of call target.

@kitsonk
Copy link
Contributor

kitsonk commented Sep 23, 2016

@sccolbert did that ever work? I think what you are proposing is covered by #5296 which is still just a proposal.

@sccolbert
Copy link

@kitsonk I could have sworn it used to be translated to a foo.apply(void 0, values) call...

@sccolbert
Copy link

For example, this compiles fine on TS 1.8:

var values: number[] = [1, 2, 3, 4, 5];
var data: number[] = [];

data.push(...values);

But as you mentioned, the original code I posted does not. Which is doubly strange :)

@jasongrout
Copy link

@mhegazy
Copy link
Contributor

mhegazy commented Sep 23, 2016

this is an issue with the playground. we recently updated to the latest version of monco-editor and that seems to set the target to ES6 all the time. i will see if i can get a fix for this soon. sorry for the confusion.

Iterators are only supported when your targeting ES6. so for .. of only works in ES6. and you should get an error indicating this otherwise.

@mhegazy mhegazy added the Docs The issue relates to how you learn TypeScript label Sep 23, 2016
@sccolbert
Copy link

sccolbert commented Sep 23, 2016

Sounds like my example is a red herring (sorry).

@mhegazy
Copy link
Contributor

mhegazy commented Sep 23, 2016

Should be fixed now. sorry about the confusion.

@mhegazy mhegazy closed this as completed Sep 23, 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
Docs The issue relates to how you learn TypeScript
Projects
None yet
Development

No branches or pull requests

5 participants