Closed
Description
Upgrading from TypeScript 2.6.2 to 2.7.1 and got a private variable scoping problem.
TypeScript Version: 2.7.1
Search Terms:
private property does not exist
Code
class Parent {
pubValue: number;
private priValue: number;
private priXXX: number;
constructor(value: number) {
this.priValue = value;
this.pubValue = 7;
}
cloneImpl(kind: boolean): Child | OtherChild {
const copy = kind ? new Child(this.priValue) : new OtherChild(this.priValue);
copy.pubValue = this.pubValue + 1;
copy.priXXX = this.priXXX;
return copy;
}
}
class Child extends Parent {
myData: number;
clone() {
return this.cloneImpl(true) as Child;
}
}
class OtherChild extends Parent {
clone() {
return this.cloneImpl(false) as OtherChild;
}
}
const child = new Child(6);
child.clone();
Expected behavior:
In typescript 2.6.2 the code was working and not generating an error. Since cloneImpl() is in the parent class it should have access to it's own private (tried with protected as well) variables.
Actual behavior:
test.ts (16,10): Property 'priXXX' does not exist on type 'Child | OtherChild'. (2339)
Playground Link:
Related Issues:
None found