Having a public getter and a private setter of the same name is prohibited in TypeScript, as already discussed in various questions here on SO.
My main programming language is C#, where this is perfectly fine. I also consider it a useful construct, and to be honest, I don't really see what a problem could be with allowing this in TypeScript as well.
Why does TypeScript prohibit this? This question is not about workarounds or alike, I just want to know the reason for this design.
Edit: A code sample can be found on this question.
There is a comment from one of TypeScript authors: https://github.com/Microsoft/TypeScript/issues/2845#issuecomment-176990923
Accessors are symetrical with properties in the type system. anything we do will need to be manifested in the type and expressible on properties. Adding new access modifiers to enable private_set/public_get would increase the complexity of the language and the learning curve, and the value gained from this would not match the added complexity.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With