Closed robpalme closed 4 years ago
This change seems fine at the surface level to me. Although, I'm unsure I have enough knowledge to speak to this change. @drwpow @FredKSchott any thoughts?
I actually wasn’t aware of this setting either! Wow that makes a big difference. I know what I’m going to be adding to all my TS projects now! 😄
Though any time you change output it can be risky, I don’t anticipate any problems with this change, because as stated, the end result is just that your output more closely matches your code, which is always a safe bet.
Errrrrrrr it doesn't look like class fields are supported in Node v10, a version that we still need to support. Basing this off of https://node.green/ (public instance class fields)
Hmm should we revert this?
Does Node need to parse these classes? I thought this was just for web code?
Oh, thanks for the sanity check! I'd thought that this was our master tsconfig for everything, including the CLI. If it's just this one TS template, then it's not broken our CLI.
Larger question then: We don't currently use TypeScript to build our frontend projects. Instead, that template is using our internal esbuild plugin to build, which I don't believe reads from tsconfig. So, I think this was a no-op?
This option
"useDefineForClassFields": true
combined with"target": "esnext"
ensures that modern class syntax is emitted.This option ensures browser and Node semantics are respected. Without this option, TypeScript will down-level class field declarations into constructor assignments.
Example input:
class C { field = 1; }
class C { constructor() { this.field = 1; } }
class C { field = 1; }
You can test this in the TypeScript playground. https://www.typescriptlang.org/play/index.html?target=99#code/LAKFGMBsEMGdYAQGEEG8EDMCWBTSATBAXgQEYEBfIA