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.
I'll have to fix the playground up, but make sure that
downlevelIteration on.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.
Most helpful comment
I'll have to fix the playground up, but make sure that
downlevelIterationon.es2015for yourliboption.