Skip to content

property accessor of subclass instance should return base's class property value, but uses a subclass' getter #36399

Closed
@abobr

Description

@abobr

TypeScript Version: 3.7.2

Search Terms:
getter
property accessor

Expected behavior:
should return value from base class A, which for the example provided is 10

Actual behavior:
returns value from class B, which for the example provided is 200

Related Issues:
#36346
#29305

Code

class A {
    a = 10;
}

class B extends A {
    _a = 200;
    get a() {
        return this._a;
    }
    set a(v) { this._a = v; }
}


console.log(new B().a);
Output
"use strict";
class A {
    constructor() {
        this.a = 10;
    }
}
class B extends A {
    constructor() {
        super(...arguments);
        this._a = 200;
    }
    get a() {
        return this._a;
    }
    set a(v) { this._a = v; }
}
console.log(new B().a);
Compiler Options
{
  "compilerOptions": {
    "noImplicitAny": true,
    "strictNullChecks": true,
    "strictFunctionTypes": true,
    "strictPropertyInitialization": true,
    "strictBindCallApply": true,
    "noImplicitThis": true,
    "noImplicitReturns": true,
    "useDefineForClassFields": false,
    "alwaysStrict": true,
    "allowUnreachableCode": false,
    "allowUnusedLabels": false,
    "downlevelIteration": false,
    "noEmitHelpers": false,
    "noLib": false,
    "noStrictGenericChecks": false,
    "noUnusedLocals": false,
    "noUnusedParameters": false,
    "esModuleInterop": true,
    "preserveConstEnums": false,
    "removeComments": false,
    "skipLibCheck": false,
    "checkJs": false,
    "allowJs": false,
    "declaration": true,
    "experimentalDecorators": false,
    "emitDecoratorMetadata": false,
    "target": "ES2017",
    "module": "ESNext"
  }
}

Playground Link: Provided

Metadata

Metadata

Assignees

No one assigned

    Labels

    QuestionAn issue which isn't directly actionable in code

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions