Skip to content

yield*: Delegating to other generators is not an array #17585

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
JPeer264 opened this issue Aug 3, 2017 · 4 comments
Closed

yield*: Delegating to other generators is not an array #17585

JPeer264 opened this issue Aug 3, 2017 · 4 comments

Comments

@JPeer264
Copy link

JPeer264 commented Aug 3, 2017

TypeScript Version: 2.4.0 / nightly (2.5.0-dev.201xxxxx)
This issue might be a duplicate of #17276 (but it addresses another issue)

Code

The following example is straight out of the MDN docs and copied it right into TS Playground:

function* g1() {
  yield 2;
  yield 3;
  yield 4;
}

function* g2() {
  yield 1;
  yield* g1(); // <- gives an error: "Type 'IterableIterator<>' is not an array type"
  yield 5;
}

var iterator = g2();

Expected behavior:
Expect that the error won't appear.

Actual behavior:
Typescript throws an error that g1() is not an array type.

@DanielRosenwasser
Copy link
Member

DanielRosenwasser commented Aug 3, 2017

I'll have to fix the playground up, but make sure that

  1. you have downlevelIteration on.
  2. you're using es2015 for your lib option.

@JPeer264
Copy link
Author

JPeer264 commented Aug 4, 2017

downlevelIteration was not set. That solved it. Thanks.

@DanielRosenwasser The documentation about generators are not there yet, should I update those?

@JPeer264 JPeer264 closed this as completed Aug 4, 2017
@TomasHubelbauer
Copy link

I wish this was better documented, or ideally, the error message was much better. I keep running into this here and there and it would be really cool if the compiler could just let me know to enable this to make it work.

@rdsedmundo
Copy link

Definitely agree with you @TomasHubelbauer. I had the same problem, and fortunately this was posted here before, otherwise, I'd spent so much time to figure out what was the real problem.

@microsoft microsoft locked and limited conversation to collaborators Jul 26, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants