-
Notifications
You must be signed in to change notification settings - Fork 13k
Open
Labels
BugA bug in TypeScriptA bug in TypeScriptRescheduledThis issue was previously scheduled to an earlier milestoneThis issue was previously scheduled to an earlier milestone
Milestone
Description
Pointed out by @rbuckton on #50971, based on the repro from that bug. When targetting ES2022 or higher, and leaving useDefineWithClassFields: true (the default) for that target:
class Helper {
create(): boolean {
return true
}
}
export class Broken {
constructor(readonly facade: Helper) {
console.log(this.bug)
}
bug = this.facade.create()
}
new Broken(new Helper)
Produces
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.Broken = void 0;
class Helper {
create() {
return true;
}
}
class Broken {
facade;
constructor(facade) {
this.facade = facade;
console.log(this.bug);
}
bug = this.facade.create();
}
exports.Broken = Broken;
new Broken(new Helper);
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 = void 0;
class Helper {
create() {
return true;
}
}
class Broken {
facade;
bug;
constructor(facade) {
this.facade = facade;
this.bug = this.facade.create();
console.log(this.bug);
}
}
exports.Broken = Broken;
new Broken(new Helper);
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.
NicBright, snarbies, AlexanderFarkas, robintown and Alexandreee100
Metadata
Metadata
Assignees
Labels
BugA bug in TypeScriptA bug in TypeScriptRescheduledThis issue was previously scheduled to an earlier milestoneThis issue was previously scheduled to an earlier milestone