Skip to content

Unable to use class decorator with static member functions #11322

Description

@ahagelstein

TypeScript Version: typescript@2.1.0-dev.20161102

Code

@testDecorator()
export class TestClass {

    public static create() {

        return new TestClass();
    }
}

Expected behavior:

typescript@2.0.6 generates the correct code. Here the static function "create" uses the decorated constructor function (the variable declared in the first line).

var TestClass = (function () {
    function TestClass() {
    }
    TestClass.create = function () {
        return new TestClass();
    };
    TestClass = __decorate([            <-- correct position
        testDecorator()
    ], TestClass);
    return TestClass;
}());
exports.TestClass = TestClass;

Actual behavior:

typescript@2.1.0-dev.201620161102 generates the wrong code. Here the static function "create" uses the variable declared in the first line, but this is not the decorated constructor function.

var TestClass = (function () {
    function TestClass() {
    }
    TestClass.create = function () {
        return new TestClass();
    };
    return TestClass;
}());
TestClass = __decorate([           <-- wrong position
    testDecorator()
], TestClass);
exports.TestClass = TestClass;

For a detailed code sample look at #10840.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions