Closed
Description
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
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