Generator functions which have a return type of a union of Iterator/AsyncIterator have a yield type of never #34984
Labels
Needs Investigation
This issue needs a team member to investigate its status.
TypeScript Version: 3.7.2
Search terms: generator iterator asynciterator type union never
Code
example.ts
A type alias which is a union of
Iterator
andAsyncIterator
is used as the return type of a synchronous generator.Expected behavior:
Code compiles.
Actual behavior:
If you replace
NumberIterator
withNumberGenerator
as the return type the function above, the code correctly type-checks. Something is wrong here.Playground Link:
https://www.typescriptlang.org/play/index.html?target=99&ssl=5&ssc=2&pln=1&pc=1#code/C4TwDgpgBAcgrgWwEYQE4ElhoIbAPapQC8UmO+qAPAHaIqoB8UAPlAIIDOI1AxmargI06aBgG4AUBIBmcXsACWealABUtZGg4AKAJQAuWCIxYBFKAG8JUG1BAKIAGwAmUAIySAvkA
The playground link won’t work because the playground doesn’t support async iterators yet (microsoft/TypeScript-Website#15).
Related Issues:
#30790 Strongly-typed iterator PR
The text was updated successfully, but these errors were encountered: