Typescript: yield*: Delegating to other generators is not an array

Created on 3 Aug 2017  路  4Comments  路  Source: microsoft/TypeScript

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.

Most helpful comment

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.

All 4 comments

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.

downlevelIteration was not set. That solved it. Thanks.

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

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.

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.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

kimamula picture kimamula  路  147Comments

Taytay picture Taytay  路  174Comments

rbuckton picture rbuckton  路  139Comments

born2net picture born2net  路  150Comments

blakeembrey picture blakeembrey  路  171Comments