Union of Generator and AsyncGenerator introduces spurious undefined next() value path #42439
Labels
Fix Available
A PR has been opened for this issue
Needs Investigation
This issue needs a team member to investigate its status.
Rescheduled
This issue was previously scheduled to an earlier milestone
Milestone
Bug Report
I was creating a coroutine-based interactive prompt library. It can consume either synchronous or asynchronous co-routines.
There doesn't seem to be any runtime issue associated with this approach, (in some configurations the library harmlessly awaits on a synchronous generator.next()).
However, any function which is declared as fulfilling a union of async+sync generators faces a compile error when a spurious
undefined
value is indicated as possible from ayield
even though the next() call only accepts strings.🔎 Search Terms
yield, undefined, typescript, asyncgenerator, generator
🕗 Version & Regression Information
⏯ Playground Link
Playground link with relevant code
💻 Code
🙁 Actual behavior
Compiler reports
Type 'string | undefined' is not assignable to type 'string'.
🙂 Expected behavior
I don't believe this possible execution path is actually made possible by the union, since it is not possible in either of the unioned cases.
The text was updated successfully, but these errors were encountered: