-
Notifications
You must be signed in to change notification settings - Fork 12.8k
Switch default for useDefineForClassFields
in ESNext
#34787
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
Class fields aren't stage 4 yet. Moving to 3.9. Edit: Still not stage 4. I'll move to 4.4 when that milestone gets created. |
This isn't mentioned in the RC notes for 3.9- has it been bumped to a later version? |
Don't think this was done in 3.9 - @sandersn? |
FYI, we plan to switch the equivalent Babel option to |
See also #41788, which will be fixed by this. |
Hey everyone, sorry, I know I shouldn't ask questions on issues (where should I ask them?) but I was wondering one thing. class SomeClass {
private prop1 = 'default';
private prop2?: string
} would emit: class SomeClass {
constructor() {
this.prop1 = 'default';
}
} without me having to add |
@guilhermesimoes this is a perfect question for Stack Overflow since it results in a yes/no answer that is recorded for the future and can be updated if needed. |
2484210 changed default for useDefineForClassFields which broke my code and took me more than 1 hour to find the reason. // TS 4.3.0-beta
class A { a: string } // => class A { }
// TS 4.3.2
class A { a: string } // => class A { a } Such patterns are commonly used with decorators class MyComponent {
@property() a: string;
} It's ok to introduce break changes and it's easy to revert to the old behavior too. The problem is that the release note said nothing about this. If it's expected, please note it somewhere. Thanks. |
This has shipped in TypeScript 4.3.1‑rc, so it probably should’ve been kept in the TypeScript 4.3.1 milestone. |
Just ran into this as a bug. Was using Alternatively, if there were a way to define the types of class properties without buying into the whole TC39 class properties spec, that would be fantastic. |
You can write class A {
declare x: string;
} |
@nicolo-ribaudo One potential option would be to allow us to define properties via sibling interface: interface Point {
x: number;
y: number;
}
class Point {
constructor() {
this.x = 0;
// the absence of this line should cause an error
// this.y = 0;
}
} |
You can do that already. It’s used in the |
@ExE-Boss |
Class fields moved to stage 4 in the April 2021 meeting, slated for publication in ES2022. |
For reference, this was fixed by PR #42663 and released in TypeScript 4.3. |
Originally posted by @sandersn in #27644 (comment)
useDefineForClassFields
should be switched to true when targeting ESNext.The text was updated successfully, but these errors were encountered: