Inheritance and private/public attributes - Need protected

Topics: Language Specification
Feb 1, 2014 at 4:37 PM
Hi. i'm using inheritance between two classes, the first (Lang) class declares a variable called _parse, of course, LangClient._parse doesn't exists. But I can't create it.

error TS2141: Class 'LangClient' cannot extend class 'Lang':
Types 'LangClient' and 'lang.Lang' define property '_config' as private.
But, just why? I declare a var private in the parent, I should be able to declare the same private in its childs.

Okay, so what? I have to declare all my functions and attributes as public in the parent class if I want to the childs to be able to use them, but they are no private anymore...

I think that we need a protected attribute, it's just impossible to make complex inheritance without the protected attribute...

I don't want to make everything public to be able to use inheritance, that's really bad to do that, and that's what I did since the start because I didn't find any better solution. (Any solution at all actually...)
Feb 1, 2014 at 5:11 PM
Ok, I definitely don't get it.

I use private attributes on methods and attributes, with the same inheritance.

But I improved my POO (better source code), so I don't call the private attributes/methods from the child.

It works... So, that means that even if they are private, the child get them.

I'm not sure to understand everything here... Or, I'm pretty sure to don't understand anything at all.

I guess the source code could help:

Lang (Parent)


If I wanted, from LangServer to call a private attributes/method, I'm sure I couldn't. So, what to do in this case? Because the improvment of my source code solved the issue, I don't call anymore private methods/attr directly from the child.

What would be your solution if I had to do it?
Feb 1, 2014 at 5:14 PM
This is a well known problem of typescript language.
You need to choose a new name for private variable in the descendant.
The second proble is the lack of protected members so all the properties are exposed to clients.
P.S. - You can not make them private because they will become inaccesible in derived classes.
Feb 1, 2014 at 5:19 PM
Edited Feb 3, 2014 at 2:55 PM
the only solution is to wait till the team will introduce protected members and maybe internal members.
P.S. I'm crossing my fingers.