-
Notifications
You must be signed in to change notification settings - Fork 13.2k
Description
Bug Report
π Search Terms
async generator return promise
π Version & Regression Information
- This is the behavior in every version available in the playground
β― Playground Link
Playground link with relevant code
π» Code
/// <reference lib="esnext" />
async function* fn() {
yield* [1]
return 3
}
async function test() {
const it = fn()
console.log(await it.next())
console.log(await it.return(Promise.resolve(2)))
}
test()π Actual behavior
When transformed by TypeScript to ES2017, this code prints the following:
{value: 1, done: false}
{value: Promise, done: true}
π Expected behavior
When run natively, this code prints the following:
{value: 1, done: false}
{value: 2, done: true}
I discovered this bug when implementing async generator transformation for esbuild. I was running relevant test262 tests through both TypeScript and esbuild's transformations and comparing the differences. There are other TypeScript-only test failures as well but they mostly involve weird uses of the API where getters throw errors, which doesn't seem like something that would come up in practice. So I'm only reporting this bug because this seems like more of an important correctness issue. Let me know if you'd like to know about the other test failures too.