Skip to content

Playground: Should support looping for generator #30079

Closed
@lanshunfang

Description

@lanshunfang

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:

Metadata

Metadata

Assignees

No one assigned

    Labels

    DuplicateAn existing issue was already created

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions