Skip to content

Suggestion: Prevent hiding super class properties and methods #9060

Closed
@MKuenzi

Description

@MKuenzi

Code

class A
{
   public member = {};
   public click = () =>
   {
   }

   constructor()
   {
      member.a = "Member";
      document.body.addEventListener("click", this.click);
   }
}

class B extends A
{
   public member = {};
   public click = () =>
   {
       // Implementer of subclass expects this to get called on body click
   }

   constructor()
   {
      super();
      console.log(this.member.a) // would print undefined
   }
}

It would be nice if we were able to generate a warning or error to say that B's member is hiding A's member, as well as the fact that B's click is hiding A's click. I'm not sure whether a new keyword would be appropriate, or just an option in tsconfig.json to generate an error or warning would make me happy.

Not having this has lead me to some head scratching to why things aren't working as I rearrange how things inherit from each other due to me not noticing that I have redefined a method or property in the subclass.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Design LimitationConstraints of the existing architecture prevent this from being fixed

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions