Skip to content

Static variable used inside instance method of a decorated subclass, will introduce run time errors. #16417

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
joeuy opened this issue Jun 9, 2017 · 2 comments
Assignees
Labels
Bug A bug in TypeScript Fixed A PR has been merged for this issue High Priority

Comments

@joeuy
Copy link

joeuy commented Jun 9, 2017

TypeScript Version: 2.4.0-dev.20170609

Code

function decorate(target) { }

class A { }

@decorate
class B extends A {
    private static readonly STATIC = 'value';
    foo() {
        return B.STATIC;
    }
}

Actual behavior: (compiled js)
look below: __extends(B, _super); is called with hoisted B = undefined.

var __extends = (this && this.__extends) || (function () {
    var extendStatics = Object.setPrototypeOf ||
        ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
        function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
    return function (d, b) {
        extendStatics(d, b);
        function __() { this.constructor = d; }
        d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
    };
})();
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
    var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
    if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
    else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
    return c > 3 && r && Object.defineProperty(target, key, r), r;
};

function decorate(target) { }
var A = (function () {
    function A() {
    }
    return A;
}());
var B = (function (_super) {
    __extends(B, _super);
    var B = B_1 = function B() {
        return _super !== null && _super.apply(this, arguments) || this;
    };
    B.prototype.foo = function () {
        return B_1.STATIC;
    };
    B.STATIC = 'value';
    B = B_1 = __decorate([
        decorate
    ], B);
    return B;
    var B_1;
}(A));
@RyanCavanaugh RyanCavanaugh added Bug A bug in TypeScript High Priority labels Jun 12, 2017
@mhegazy mhegazy added this to the TypeScript 2.4.1 milestone Jun 12, 2017
@normalser
Copy link

Having the same issue. Had to downgrade tsc version.
Seems it got introduced with 2.4.0-dev.20170601

@basarat
Copy link
Contributor

basarat commented Jun 14, 2017

Maybe there should be a "run emitted JS" category of tests. Neverthless thanks for the quick fix 🌹 ❤️

@microsoft microsoft locked and limited conversation to collaborators Jun 14, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Bug A bug in TypeScript Fixed A PR has been merged for this issue High Priority
Projects
None yet
Development

No branches or pull requests

6 participants