Skip to content

This and super should not be allowed in method/property decorators #2601

@mhegazy

Description

@mhegazy

the decorator does not execute in the context of the method or the constructor. at design time this and super refers to the class scope, but at run time they do not.

class Test{
    private serialize(target: Function, key: string| symbol, descriptor: PropertyDescriptor) {
    }

    @this.serialize
    public method(fileName: string, position: number): any {
    }
}

generates this does which is incorrect

var Test = (function () {
    function Test() {
    }
    Test.prototype.serialize = function (target, key, descriptor) {
    };
    Test.prototype.method = function (fileName, position) {
    };
    Object.defineProperty(Test.prototype, "method", __decorate([this.serialize], Test.prototype, "method", Object.getOwnPropertyDescriptor(Test.prototype, "method")));
    return Test;
})();

Metadata

Metadata

Assignees

Labels

BugA bug in TypeScriptFixedA PR has been merged for this issue

Type

No type
No fields configured for issues without a type.

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions