Is there a way to have a private setter for a property in TypeScript?
class Test
{
private _prop: string;
public get prop() : string
{
return this._prop;
}
private set prop(val: string)
{
//can put breakpoints here
this._prop = val;
}
}
Compiler complains that visibility for getter and setter don't match. I know I can just set the backing field, but but then I can't set breakpoints when the value is set.
I though about using an interface to hide the setter, but interfaces can only define a property, not whether it has a getter on setter.
Am I missing something here? There doesn't seem to be any reason to not allow private setters, the resulting JS doesn't enforce visibility anyway, and seems better that the current alternatives.
Am I missing something? If not is there a good reason for no private setters?