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 {}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.
Photo by Andrew Nemeth on Unsplash
Related Articles
Abstract Classes in Typescript
In Typescript, the classes can inherit from another class to share methods and properties between classes. Also, Typescript support abstract class. Let me show you why and when to use it. For example, we have a base class Subscription and create the ...
3 Ways of Type Transformation in Typescript
When we use types or interfaces, the typescript compiler enforces the object fit with them to avoid runtime errors for missing fields. Sometimes we want the flexibility to create an object without breaking the contract with the interface type. For ex...
Avoid Check Null or Undefined In Typescript using Optional Chaining and Nullish Coalescing
TypeScript offers powerful features that make code more concise and efficient. Two such features, optional chaining and nullish coalescing, play a vital role in handling data effectively. In this article, we'll explore these features within the conte...
Real Software. Real Lessons.
I share the lessons I learned the hard way, so you can either avoid them or be ready when they happen.
Join 13,800+ developers and readers.
No spam ever. Unsubscribe at any time.