Skip to content
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

Invalid field initialization order in descendant class #10634

Closed
chebum opened this issue Aug 31, 2016 · 1 comment
Closed

Invalid field initialization order in descendant class #10634

chebum opened this issue Aug 31, 2016 · 1 comment
Labels
Working as Intended The behavior described is the intended behavior; this is not a bug

Comments

@chebum
Copy link

chebum commented Aug 31, 2016

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));
@RyanCavanaugh RyanCavanaugh added the Working as Intended The behavior described is the intended behavior; this is not a bug label Aug 31, 2016
@RyanCavanaugh
Copy link
Member

This is not how classes work. In ES6 it is illegal to use this before calling super.

See also #1617

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Working as Intended The behavior described is the intended behavior; this is not a bug
Projects
None yet
Development

No branches or pull requests

2 participants