Skip to content

Playground: Should support looping for generator #30079

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

Closed
lanshunfang opened this issue Feb 25, 2019 · 2 comments
Closed

Playground: Should support looping for generator #30079

lanshunfang opened this issue Feb 25, 2019 · 2 comments
Labels
Duplicate An existing issue was already created

Comments

@lanshunfang
Copy link

lanshunfang commented Feb 25, 2019

TypeScript Version: 3.4.0-dev.201xxxxx

Search Terms:

  • Generator
  • Generator loop
  • Generator for
  • Generator iterator

Code

// A *self-contained* demonstration of the problem follows...
// Test this by running `tsc` on the command-line, rather than through another build tool such as Gulp, Webpack, etc.
const gen = function* () { 
    yield 2;
    yield 3;
}
const genInst = gen();
for (let i of genInst) {
    console.log(i);
}

Expected behavior:

  • No error is thrown
  • console.log should output yield value 2, 3
  • Just try it in Chrome debugger

Actual behavior:

  • TSC: throw type error
  • error TS2569: Type 'IterableIterator<2 | 3>' is not an array type or a string type.

Playground Link:

Related Issues:

@lanshunfang
Copy link
Author

With --downlevelIteration in tsc (not playground, this problem solved)

@lanshunfang lanshunfang changed the title Should support looping for generator Playground: Should support looping for generator Feb 25, 2019
@lanshunfang
Copy link
Author

Duplicated with #18209

@RyanCavanaugh RyanCavanaugh added the Duplicate An existing issue was already created label Feb 25, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Duplicate An existing issue was already created
Projects
None yet
Development

No branches or pull requests

2 participants