Skip to content

Wrong field value in inherited constructor's submethod and after #9455

Closed
@mikolaj-milewski

Description

@mikolaj-milewski

TypeScript Version: 1.8.10

Code

// A *self-contained* demonstration of the problem follows...
abstract class A {
    constructor() {
        this.onCreate();
    }

    abstract onCreate();
}

class B extends A {
    private field = 'foo';

    onCreate() {
        console.log(this.field);
        this.field = 'bar';
    }

    echo () {
        console.log(this.field);
    }
}

let b: B = new B();
b.echo();

Expected behavior:
Console prints out:

foo
bar

Actual behavior:
Console prints out:

undefined
foo

Metadata

Metadata

Assignees

No one assigned

    Labels

    DuplicateAn existing issue was already created

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions