-
Notifications
You must be signed in to change notification settings - Fork 32.8k
Use useDefineForClassFields
compiler options
#186726
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
Comments
Is this microsoft/TypeScript#50971? TS may not emit compile errors for all cases that |
Now I am scared |
According to microsoft/TypeScript#45995 (comment), it looks like |
I've started working through these errors. There are about 500 errors in this codebase when you set I'm guessing I could resolve these in a day or two. Is this a PR you guys would be amenable to? To be clear, the PR would just be to make things compile with that setting, not actually turn it on. I expect you'd want additional testing to verify everything works as expected when emitting true JS public class fields. |
@trevorade FYI - we have finally finished #243049 and we have a "shadow compile" in CI that sets Tho, compiling successfully and running successfully are two different pairs of shoes. I gave it a quick try yesterday and found more init-order issues that only surface during runtime. Maybe I misunderstood but are you already compiling and running with defined class fields in your fork? |
Uh oh!
There was an error while loading. Please reload this page.
Intro
Some background info: https://www.typescriptlang.org/docs/handbook/release-notes/typescript-3-7.html#the-usedefineforclassfields-flag-and-the-declare-property-modifier and https://www.typescriptlang.org/tsconfig#useDefineForClassFields
The gist is that JavaScript now supports declaring class fields (before they were implicitly defined by assignment). In TypeScript we always declared class fields but the JS variant is slightly different. The sample below will not work anymore because TS constructor fields get now declared too.
The sample above yields a compile error because the newly emitted JS code will be this
The old code would have been (currently is)
Why
There is some hope that explicitly declared class properties prevents shape mutations which leads to deopting
Adoption
We have ~280 compile errors when enabling
useDefineForClassFields
which can be fixed with ease. Move field assignment that depends on a ctor-defined-field into the ctor itselfThe text was updated successfully, but these errors were encountered: