Why I don't get compile time error when I am not implementing some method from my interface which is implemented in base class?

Viewed 45

I have the following code

interface IDownload {
  downloadFile(): void;
}

class BaseClass implements IDownload {
  downloadFile(): void {
    console.log('some logic here');
  }
}

class Sub extends BaseClass {

}

so my sub class has access to the methods from BaseClass because we are extending from that class.

My base class implement some method from interface.

When i try to extend the class and implement again the same interface

class Sub extends BaseClass implements IDownload {

}

I don't get compile time error that i need to implement the method from IDownload. I guees it is like that because it sees that the base class already implements it.

But i want to have that check also here in my sub class because i want to have the interface contract in the base class where all the methhods will exist on the sub class.

How can i do this ?

1 Answers

If you want all the implementation in the sub class, why don't you just implement the interface in the sub class?

interface IDownload {
  downloadFile(): void;
}

class BaseClass  {

}

class Sub extends BaseClass implements IDownload {
  downloadFile(): void {
    console.log('some logic here');
  }
}
Related