Skip to content

Class property inheritance and constructor usage #16190

Closed
@albohlabs

Description

@albohlabs

TypeScript Version: 2.3

Code

class A {
    prop = 'A';

    constructor() {
	this.outputProp();
    }

    outputProp() {
	console.log(this.prop);
    }
}

class B extends A {
   prop = 'B';

    constructor() {
        super();
	this.outputProp();
    }
}

new B();

Expected behavior:

The output of console.log should be the value of prop from class B.

I would expect that a method call from the constructor is not evaluated before the class properties are assigned.

Actual behavior:

console.log output is A.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions