Here is an example of an issue I encountered while working with private properties in TypeScript.
I expected that only the public properties would be visible in my object output, similar to normal encapsulation.
My aim here is to include the property with a setter and getter as part of the exposed API of my class rather than the private property (similar to C#).
class MyClass {
public otherProp: boolean;
constructor() {
this.otherProp = false;
this._privateProp = false;
}
private _privateProp: boolean;
get publicProp() : boolean {
return this._privateProp;
}
set publicProp(values : boolean) {
this._privateProp = values;
}
}
let x: MyClass = new MyClass();
console.log(x); // MyClass {otherProp: false, _privateProp: false}
// Expected output: MyClass {otherProp: false, publicProp: false}