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...
Next.js Performance: What the Defaults Don’t Solve for You
Next.js gives you strong performance defaults. But fast by default doesn’t mean fast always. Over the last few days, I’ve been working with Next.js and React Server Components, assuming the framework would handle most performance concerns for me. And...
How To Test Private Methods in Typescript
Sometimes we need to test a private method, and Yes, maybe it's not a best practice, but in my case, I have a situation when I need to add a test to my private method, and if you have the same situation I hope it helps you. My example is a service wi...
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.