Handle breaking change in class property runtime behavior · Issue #27644 · microsoft/TypeScript (original) (raw)

From #12212 (comment) @joeywatts:

class A { property = 'some string'; } class B extends A { property; } const instanceB = new B(); // "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 [@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)