-
Notifications
You must be signed in to change notification settings - Fork 12.6k
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
Compiled generators does not have correct constructor name #15088
Labels
Milestone
Comments
Is there any updates ? |
This also applies to async functions: TypeScript: async function a() {}
a.constructor.name // "Function" Latest version of Chrome: async function a() {}
a.constructor.name // "AsyncFunction" |
RyanCavanaugh
added
Won't Fix
The severity and priority of this issue do not warrant the time or complexity needed to fix it
and removed
Bug
A bug in TypeScript
labels
Feb 23, 2024
This doesn't seem like an important scenario for modern JS development - folks can either target ES6 which is supported basically everywhere, or use an alternate transpiler with stricter adherence semantics if this is important for their scenario. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
TypeScript Version: 2.3.0-dev.20170407
Expected behavior:
Code logs "GeneratorFunction" when compiled to ES5.
Actual behavior:
Code logs "Function" when compiled to ES5.
Description:
Babel compiles this code so that the constructor name is set correctly. They do that by including a small run-time function that marks all generator functions as such. The source code for the marking function can be found here.
Compiling this per the specification is important since using the constructor name is the only way to check if a certain function is a generator function or not. See for instance this SO question and answer.
The text was updated successfully, but these errors were encountered: