-
Notifications
You must be signed in to change notification settings - Fork 12.5k
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
Switch default for useDefineForClassFields
in ESNext
#34787
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? |
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: