DEV Community 👩‍💻👨‍💻

Cover image for Difference between 'extends' and 'implements' in TypeScript
Dany Paredes
Dany Paredes

Posted on

Difference between 'extends' and 'implements' in TypeScript

Today, a friend ask about the difference between extends and implements.

class Media {
  format: string;
}
class Video extends Media {}
class Image implements Media {}
Enter fullscreen mode Exit fullscreen mode

The short answer for him was:

extends: The class get all these methods and properties from the parent, so you don't have to implement.

implements: The class has to implement methods and properties.

I hope this is can help someone with the same question.

Top comments (2)

Collapse
 
behzadkhodapanah1993 profile image
Behzad Khodapanah • Edited on

Thanks for helpful post!
I want add more info.
When we are using EXTENDS: the class that extended by become the parent, and there our class has access to all the properties and methods.
When we are using IMPLEMENTS: the class has to implement the destination class methods and properties without being the child of that class!

Final thought: Extends is more like inheritance and Implements more like polymorphism.

Collapse
 
diatemba99 profile image
Diatemba99

Thanks you!! It's useful

Top 7 Badge

Earn our Top 7 Badge!

Write a post that gets featured in our weekly "must-reads" and you can earn this badge for your profile. 😎