Angel Angel Angel Angel - 8 months ago 30
TypeScript Question

typescript derived class cannot have the same variable name?

Why can't typescript derived class have the same variable name? Even these members are private. Is there an alternative to this, or am I doing something wrong?

class ClassTS {

private nom: string = "ClaseTS";

constructor() {


class ClassTSDer extends ClassTS {

private nom: string = "ClassTS";

constructor() {

I found this while practising with TS.

Class 'ClassTSDer' incorrectly extends base class 'ClaseTS'. Types
have separate declarations of a private property 'nom'. ClassTSDer

class ClassTSDer

you could, use protected; yes but if I do not want to use protected, would I have to use another name?

Answer Source

The properties must have different names.

Remember that at runtime, JavaScript class instances are just objects, and objects are just mappings from key to value. The property names are the key, and you can't have two different keys with the same name.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download