Closed
Description
Bug Report
π Search Terms
decorator, decorators
π Version & Regression Information
- This is using version 5.0.4
β― Playground Link
π» Code
function myDecorator(target: any) {
return function(this: any, ...args: any[]) {
return target.apply(this, args);
}
}
export class MyClass {
@myDecorator
public foo() {
return 'bar';
}
}
export const myClassInstance = new MyClass();
π Actual behavior
Interestingly the Workbench doesn't reproduce the issue - but when running tsc
locally, the outputted JS code looks like this:
exports.MyClass = (() => {
var _a;
let _instanceExtraInitializers = [];
let _foo_decorators;
return _a = class MyClass {
...
},
(() => {
_foo_decorators = [someDecorator];
__esDecorate(_a, null, _foo_decorators, { ... });
})(),
_a;
});
exports.myClass = new MyClass();
Because MyClass
is now defined under the exports
object, the last line fails :'(
This only happens when a member decorator is present in the class. When the decorator is omitted, MyClass
is declared under the module scope, and then assigned to the exports object later.
π Expected behavior
I should be able to instantiate an exported class with a stage 3 decorator from within the same module.