Typescript: Exported class with a parent, decorator and self-referential static properties fails at runtime with "Object.setPrototypeOf called on null or undefined"

Created on 13 Jun 2017  路  3Comments  路  Source: microsoft/TypeScript



TypeScript Version: 2.5.0-dev.20170613

Code

class Foo {}

@bar
export class Bar extends Foo {
  static FOO = 321
  static BAR = Bar.FOO
}

function bar(x) {
  return x
}

Expected behavior:

Should compile and run.

Actual behavior:

With target ES5, this compiles into:

// helpers omitted
Object.defineProperty(exports, "__esModule", { value: true });
var Foo = (function () {
    function Foo() {
    }
    return Foo;
}());
var Bar = (function (_super) {
    __extends(Bar, _super);
    var Bar = Bar_1 = function Bar() {
        return _super !== null && _super.apply(this, arguments) || this;
    };
    Bar.FOO = 321;
    Bar.BAR = Bar_1.FOO;
    Bar = Bar_1 = __decorate([
        bar
    ], Bar);
    return Bar;
    var Bar_1;
}(Foo));
exports.Bar = Bar;
function bar(x) {
    return x;
}

And fails at runtime with Object.setPrototypeOf called on null or undefined in the __extends helper.

Compiled with 2.3.4:

// helpers omitted
Object.defineProperty(exports, "__esModule", { value: true });
var Foo = (function () {
    function Foo() {
    }
    return Foo;
}());
var Bar = Bar_1 = (function (_super) {
    __extends(Bar, _super);
    function Bar() {
        return _super !== null && _super.apply(this, arguments) || this;
    }
    return Bar;
}(Foo));
Bar.FOO = 321;
Bar.BAR = Bar_1.FOO;
Bar = Bar_1 = __decorate([
    bar
], Bar);
exports.Bar = Bar;
function bar(x) {
    return x;
}
var Bar_1;
Duplicate

Most helpful comment

Duplicate of https://github.com/Microsoft/TypeScript/issues/16417, fixed by https://github.com/Microsoft/TypeScript/pull/16496. Fix should be in typescript@next later tonight and [email protected] in two weeks.

All 3 comments

Duplicate of https://github.com/Microsoft/TypeScript/issues/16417, fixed by https://github.com/Microsoft/TypeScript/pull/16496. Fix should be in typescript@next later tonight and [email protected] in two weeks.

Just came upon this via Google Search. Shouldn't this issue be closed cuz it's a duplicate of #14617 ?

Automatically closing this issue for housekeeping purposes. The issue labels indicate that it is unactionable at the moment or has already been addressed.

Was this page helpful?
0 / 5 - 0 ratings