-
Notifications
You must be signed in to change notification settings - Fork 12.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. Weβll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Parameter decorators use incorrect async/await context, generated code has syntax error #48509
Labels
Milestone
Comments
There's also a similar case with generator functions and function decorator(a: any): any {}
function *fn(value: Promise<number>): any {
class Class {
method(@decorator(yield value) arg: number) {}
}
return Class
} Right now TypeScript reports an error but still generates valid JavaScript. It would also be good to have clarity on whether this case is supposed to work or not as well. |
1 task
This was referenced Apr 2, 2022
1 task
This was referenced Apr 2, 2022
This was referenced May 1, 2022
This was referenced May 8, 2022
This was referenced May 12, 2022
This was referenced May 15, 2022
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Bug Report
π Search Terms
parameter decorator async await context syntax error
π Version & Regression Information
β― Playground Link
Playground link with relevant code
π» Code
π Actual behavior
The above sample code is compiled without any errors by TypeScript and generates the following invalid JavaScript code, which contains a syntax error:
The specific syntax error is that
await
is used outside of anasync
function. I originally discovered this issue with the following incorrect code:That is correctly detected as an error by TypeScript, but it has the wrong suggestion:
The
async
should be added to the outer function, not to the inner method.π Expected behavior
Both the error message suggestion and the compiler's validation logic itself are incorrect about the async/await context of parameter decorators. It should be the context of the class, not the context of the method, because the generated decorator code is inserted as sibling statements of the class. In other words adding
async
on the outer function like this should be the only valid way to fix this code:The additional context here is that I'm the developer behind esbuild and I'm trying to reverse-engineer how I should be converting TypeScript code to JavaScript code. A user sent me an issue with a similar problem in esbuild: evanw/esbuild#2147. When investigating that bug I discovered this bug in TypeScript and reported it here.
The text was updated successfully, but these errors were encountered: