You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I encountered an inconsistency in the TypeScript compiler when using static properties in abstract classes
The following code produces an error in IdGenerator_1 but not in IdGenerator_2
abstractclassIdGenerator_1{privatestaticlastId: number=0;privateid: number;// Errorconstructor(){this.setGeneratedId();}privatesetGeneratedId(){IdGenerator_1.lastId++;this.id=IdGenerator_1.lastId;}publicgetId(): number{returnthis.id;}}abstractclassIdGenerator_2{privatestaticlastId: number=0;privateid: number;// No Errorconstructor(){IdGenerator_2.lastId++;this.id=IdGenerator_2.lastId;}publicgetId(): number{returnthis.id;}}
🙁 Actual behavior
The compiler produces an error for IdGenerator_1 but not for IdGenerator_2
🙂 Expected behavior
Both IdGenerator_1 and IdGenerator_2 should compile without errors, as they are functionally identical
Additional information about the issue
No response
The text was updated successfully, but these errors were encountered:
🔎 Search Terms
Property 'X' has no initializer and is not definitely assigned in the constructor
🕗 Version & Regression Information
⏯ Playground Link
https://www.typescriptlang.org/play/?ts=5.8.0-dev.20250125#code/IYIwzgLgTsDGEAJYBthjAgkgEwOIFMA7fGCAeygH0BGBAbwCgFmEAHKASwDdgJ8FIvDrASpIOAFwJCAVwC2IEggC8CAAwBuJi3bde-DtimyFJDQgD0FhAFEoUCg23NYZQpCgz4FABQBKemcWZggACw4wADowfAgCYlJ8bBx-LWCAXydg3R4+AVj4kn1k7H9A4OCcQtIKGkixCBwAaia0ipDwqMMVLDwiIvIqanq0Ruw25kyg1hkQZGEEAHNYlL9jeUUocvaEKFiZKEIEMIjIwwmETKnQDzhEFDQMKv6aqgAmbeYc-QEIIREGpJpBslKpNNNOLkDEZgaYoOYrAgAHJkWz2RxBVzuaBeQZlRg7XrVXi1N4jcTYFoXYInLrYHrPBIk97ksYXKbZWbzETLMb+dZwz4VPYQA5HWlncZBK5AA
💻 Code
I encountered an inconsistency in the TypeScript compiler when using static properties in abstract classes
The following code produces an error in
IdGenerator_1
but not inIdGenerator_2
🙁 Actual behavior
The compiler produces an error for
IdGenerator_1
but not forIdGenerator_2
🙂 Expected behavior
Both
IdGenerator_1
andIdGenerator_2
should compile without errors, as they are functionally identicalAdditional information about the issue
No response
The text was updated successfully, but these errors were encountered: