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");
}
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:
🔎 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-betaand5.0.2. Not applicable to prior versions.⏯ Playground Link
Playground link with relevant code
💻 Code
🙁 Actual behavior
Constructor logic is duplicated:
🙂 Expected behavior
Constructor logic should not be duplicated: