Skip to content

Invalid field initialization order in descendant class #10634

Closed
@chebum

Description

@chebum

TypeScript Version: 1.8.7

Code

class A {
    a = true;   
    constructor() {
    }
}

class B extends A {
    b = true;
    constructor() {
        super();
    }
}

new B();

Expected behavior:
The b field should be set to true, then super() called.

Actual behavior:
The super constructor is called first, then b field is initialized.

Generated JS

var B = (function (_super) {
    __extends(B, _super);
    function B() {
        _super.call(this);
        this.b = true;
    }
    return B;
}(A));

Metadata

Metadata

Assignees

No one assigned

    Labels

    Working as IntendedThe behavior described is the intended behavior; this is not a bug

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions