Pointed out byRon Buckton (@rbuckton) on #50971, based on the repro from that bug. When targetting ES2022 or higher, and leaving useDefineWithClassFields: true (the default) for that target:
classHelper{create(): boolean{returntrue}}exportclassBroken{constructor(readonlyfacade: Helper){console.log(this.bug)}bug=this.facade.create()}newBroken(newHelper)Produces
"use strict";Object.defineProperty(exports,"__esModule",{value: true});exports.Broken=void0;classHelper{create(){returntrue;}}classBroken{facade;constructor(facade){this.facade=facade;console.log(this.bug);}bug=this.facade.create();}exports.Broken=Broken;newBroken(newHelper);Currently the compiler issues an error on bug = this.facade.create() to avoid the bad emit, but it might be better to change the emit when parameter properties are used:
"use strict";Object.defineProperty(exports,"__esModule",{value: true});exports.Broken=void0;classHelper{create(){returntrue;}}classBroken{facade;bug;constructor(facade){this.facade=facade;this.bug=this.facade.create();console.log(this.bug);}}exports.Broken=Broken;newBroken(newHelper);Unfortunately, this isn't standard initialisation order for class fields...so it's correct, but not standard. That's probably OK since parameter properties aren't standard.
Pointed out byRon Buckton (@rbuckton) on #50971, based on the repro from that bug. When targetting ES2022 or higher, and leaving useDefineWithClassFields: true (the default) for that target:
Produces
Currently the compiler issues an error on
bug = this.facade.create()to avoid the bad emit, but it might be better to change the emit when parameter properties are used:Unfortunately, this isn't standard initialisation order for class fields...so it's correct, but not standard. That's probably OK since parameter properties aren't standard.