Why does TypeScript prohibit a private setter for a public recipient of the same name?

Having a public recipient and a private setter with the same name is prohibited in TypeScript, as has already been discussed in various issues here on SO.

My main programming language is C #, where it's great. I also find this a useful construct, and to be honest, I really don't see what might be the problem with resolving this in TypeScript.

Why does TypeScript prohibit this? This question does not concern workarounds or the like, I just want to know the reason for this design.

Edit: sample code can be found on this question .

+8
typescript
source share
1 answer

There is a comment from one of TypeScript authors: https://github.com/Microsoft/TypeScript/issues/2845#issuecomment-176990923

Accessors are symmetric with properties in a type system. something we will need to manifest in type and express properties. Adding new access modifiers to enable private_set / public_get will increase the complexity of the language and the learning curve, and the value obtained from this will not correspond to the added complexity.

+5
source share

All Articles