From #12212 (comment)Joey Watts (@joeywatts):
classA{property='some string';}classBextendsA{property;}constinstanceB=newB();// "some string" or "undefined" ?console.log(instanceB.property);It appears from the current definition at https://github.com/tc39/proposal-class-fields that this code will print undefined.
If the proposal advances further with these semantics, we'll need to figure out a mitigation strategy, preferably sooner rather than later.
One option is to make the code as written a type error for ~2 versions and force people to write an explicit = undefined initializer, then remove the error.
Edit [Nathan Shively-Sanders (@sandersn)]:
Here is the current plan, together with what has happened so far.
TypeScript 3.6
TypeScript 3.7
TypeScript 3.8
(or, the first version after class fields reaches Stage 4)
From #12212 (comment)Joey Watts (@joeywatts):
It appears from the current definition at https://github.com/tc39/proposal-class-fields that this code will print
undefined.If the proposal advances further with these semantics, we'll need to figure out a mitigation strategy, preferably sooner rather than later.
One option is to make the code as written a type error for ~2 versions and force people to write an explicit
= undefinedinitializer, then remove the error.Edit [Nathan Shively-Sanders (@sandersn)]:
Here is the current plan, together with what has happened so far.
TypeScript 3.6
declare class C { get p(): number; }(andsetas well)TypeScript 3.7
class C extends B { declare x: number }declarewhere needed.useDefineForClassFields."useDefineForClassFields": false:"useDefineForClassFields": true:"useDefineForClassFields"defaults tofalseTypeScript 3.8
(or, the first version after class fields reaches Stage 4)
"useDefineForClassFields"defaults to true when targetting ESNext."useDefineForClassFields": false.