-
Notifications
You must be signed in to change notification settings - Fork 13.3k
Double Emit of Contructor when using Getter Decorators #53448
Copy link
Copy link
Closed
Labels
BugA bug in TypeScriptA bug in TypeScriptFix AvailableA PR has been opened for this issueA PR has been opened for this issue
Milestone
Description
Bug Report
With the implementation of Stage 3 Decorators in TS 5, using a getter decorator can result in the content of the constructor being duplicated in the emitted code, for example:
constructor() {
this.computedVal;
console.log("As will this");
__runInitializers(this, _instanceExtraInitializers);
this.computedVal;
console.log("As will this");
}🔎 Search Terms
Constructor duplicate decorators getter
🕗 Version & Regression Information
Started seeing this when I updated a library from TS 5.0-beta to TS 5.0.2.
This changed between versions 5.0-beta and 5.0.2. Not applicable to prior versions.
⏯ Playground Link
Playground link with relevant code
💻 Code
function computed(target, ctx: ClassGetterDecoratorContext) {
ctx.addInitializer(function () {
console.log("INIT")
})
return target
}
class Bla {
// Things seem to work as expected if a field or accessor is also defined,
// but additional getters/setters or methods continue to see the double emission
// name: string = ""
@computed
get computedVal() {
console.log("This will print twice")
return 3
}
constructor() {
this.computedVal
console.log("As will this")
}
}
new Bla()🙁 Actual behavior
Constructor logic is duplicated:
constructor() {
this.computedVal;
console.log("As will this");
__runInitializers(this, _instanceExtraInitializers);
this.computedVal;
console.log("As will this");
}🙂 Expected behavior
Constructor logic should not be duplicated:
constructor() {
__runInitializers(this, _instanceExtraInitializers);
this.computedVal;
console.log("As will this");
}Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
BugA bug in TypeScriptA bug in TypeScriptFix AvailableA PR has been opened for this issueA PR has been opened for this issue