-
Notifications
You must be signed in to change notification settings - Fork 13.1k
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
π Search Terms
TC39 decorators, class decorator, static members
π Version & Regression Information
This changed when started using the new TC39 decorators (non-experimental/legacy).
β― Playground Link
π» Code
function deco(hook?: any): any { }
@deco(Foo.bar)
class Foo {
public static bar() { }
}π Actual behavior
Getting the following error when the generated JS is run.
Cannot read properties of undefined (reading 'bar')
π Expected behavior
The generated code should work. Otherwise, the tsc should at least throw compilation error.
Additional information about the issue
This happens because the class decorators are listed, before the class is defined.
let Foo = (() => {
let _classDecorators = [deco(Foo.bar)]; // this seems to be causing the issue.
let _classDescriptor;
let _classExtraInitializers = [];
let _classThis;
var Foo = class {
static { _classThis = this; }
static {
const _metadata = typeof Symbol === "function" && Symbol.metadata ? Object.create(null) : void 0;
__esDecorate(null, _classDescriptor = { value: _classThis }, _classDecorators, { kind: "class", name: _classThis.name, metadata: _metadata }, null, _classExtraInitializers);
Foo = _classThis = _classDescriptor.value;
if (_metadata) Object.defineProperty(_classThis, Symbol.metadata, { enumerable: true, configurable: true, writable: true, value: _metadata });
__runInitializers(_classThis, _classExtraInitializers);
}
static bar() { }
};
return Foo = _classThis;
})();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