-
Notifications
You must be signed in to change notification settings - Fork 12.7k
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
useDefineForClassFields defaults to true in 4.2.4 #45584
Comments
The default of
This is very unlikely. You either use different versions and/or different TypeScript settings. The default for |
@MartinJohns target is the same as VS Code running 4.3.5 with VS2019 running 4.2.4 with the exact same settings and code does emit class fields. Previous versions of Typescript in both VS Code and VS2019 consistently did not emit class fields, also with the same settings. Setting Whatever default of |
Please show a repro in the playground or with |
There is issue that (I guess) should track docs for this change - #45076 |
@IllusionMH ah, thank you! I bet thatβs what @KeithHenry is talking about. The examples I tested all had initializers. Itβs a little hard to repro something without a code snippet π |
@andrewbranch it works just fine in a playground or The bug appears to only be in the weird embedded version of TypeScript that Visual Studio runs. @IllusionMH Part of what made this so hard for my team was that Is #42663 working right? Is this actually a bug in 4.3? It was the inconsistency that made this hard to bugfix, if 4.3 should default |
I don't know anything about VS2019 and especially if it uses built-in TS version or one from For VS Code it's recommended to use Workspace Version of TS And default build task (auto detected) would use TS from local
I wasn't able to reproduce thiswith next setup
class MyClass {
myField: any;
} {
"compilerOptions": {
"target": "esnext"
},
"include": [
"*.ts"
]
}
output will be as expected (implied enabled class MyClass {
myField;
} If VS Code is not configured to use workspace version and in the same time shows 4.3.5 (which is provided with VS Code 1.59.1) in status bar - I would assume that there is chance that globally installed TS version is used for compilation and it's not 4.3.5. Having simple repo with proper setup (TS in UPD. Also not reproduced class fields emit in 4.2.4
|
We're starting to see this break Lit projects. At the very least decorated fields should not emit native class fields because there is no way to metaprogram over them and the vast majority of decorators will break. |
Iβm closing this issue because itβs causing confusionβthe title is a false assertion and leaving it open may lead people to believe itβs true. If you believe thereβs a bug, please read through #45076 first, then open a new issue that clearly demonstrates the problem in a reproduceable way (demonstrated with tsc and/or the playground), following the issue template, including code samples or a link to a repository if necessary. If other tools, be they editors or external build systems, are required to demonstrate a problem with TypeScriptβs emitted JS, itβs not a TypeScript bug. Thanks! |
@andrewbranch I'm a little confused by this:
My assertion is that However, @MartinJohns said:
Are you closing this because
Where is this breaking change documented? Should or shouldn't it default to true? Assuming that this is desired behaviour and this is missing documentation I've raised #45653 |
Yes, it does. I just verified this behaviour.
The same result as Andrew had, and exactly why he asked you for a repro using tsc. |
@MartinJohns apologies, it was a bank holiday over here in the UK and when I came back the issue was closed, there didn't seem much point working on reproducing the problem when the response was that it's by design, just undocumented. |
We keep having users who have broken projects because of this. It's very frustrating. |
Bug Report
π Search Terms
useDefineForClassFields
π Version & Regression Information
β― Playground Link
Same code compiles in VS Code and command lines, it breaks in Visual Studio 2019+Typescript 4.2.4 only
π» Code
Use a
@decorator
on class properties or any code that is incompatible withuseDefineForClassFields: true
Something like:
Do not include
useDefineForClassFields
in yourtsconfig.json
at all.Run Typescript compile.
When VS2019 with TS 4.2.4 compiles JS output includes class fields, something like:
When
tsc
4.3.5 compiles for the sametsconfig
and source files it doesn't include class fields, something like:Adding
useDefineForClassFields: false
works around the issue and makes the JS output consistent.Property decorators are ignored (as per #35081).
π Actual behaviour
JS output includes class fields (as if
useDefineForClassFields
was set to true) in VS2019+TS 4.2.4JS output does not include class fields (as if
useDefineForClassFields
was set to false) in tsc 3.7 or 4.3π Expected behaviour
JS output should not include class fields unless
useDefineForClassFields
is explicitly set to true.Whatever default
useDefineForClassFields
setting is should be consistent between tsc and VS2019+TSThe text was updated successfully, but these errors were encountered: