You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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)
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
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:
https://www.typescriptlang.org/play/#src=class%20Parent%20%7B%0D%0A%20%20pubValue%3A%20number%3B%0D%0A%0D%0A%20%20protected%20priValue%3A%20number%3B%0D%0A%20%20protected%20priXXX%3A%20number%3B%0D%0A%0D%0A%20%20constructor(value%3A%20number)%20%7B%0D%0A%20%20%20%20this.priValue%20%3D%20value%3B%0D%0A%20%20%20%20this.pubValue%20%3D%207%3B%0D%0A%20%20%7D%0D%0A%0D%0A%20%20cloneImpl(kind%3A%20boolean)%3A%20Child%20%7C%20OtherChild%20%7B%0D%0A%20%20%20%20const%20copy%20%3D%20kind%20%3F%20new%20Child(this.priValue)%20%3A%20new%20OtherChild(this.priValue)%3B%0D%0A%20%20%20%20copy.pubValue%20%3D%20this.pubValue%20%2B%201%3B%0D%0A%20%20%20%20copy.priXXX%20%3D%20this.priXXX%3B%0D%0A%0D%0A%20%20%20%20return%20copy%3B%0D%0A%20%20%7D%0D%0A%7D%0D%0A%0D%0Aclass%20Child%20extends%20Parent%20%7B%0D%0A%20%20myData%3A%20number%3B%0D%0A%0D%0A%20%20clone()%20%7B%0D%0A%20%20%20%20return%20this.cloneImpl(true)%20as%20Child%3B%0D%0A%20%20%7D%0D%0A%7D%0D%0A%0D%0Aclass%20OtherChild%20extends%20Parent%20%7B%0D%0A%20%20clone()%20%7B%0D%0A%20%20%20%20return%20this.cloneImpl(false)%20as%20OtherChild%3B%0D%0A%20%20%7D%0D%0A%7D%0D%0A%0D%0Aconst%20child%20%3D%20new%20Child(6)%3B%0D%0A%0D%0Achild.clone()%3B
Related Issues:
None found