What is the difference between extends and implements in TypeScript?

Why Interviewers Ask This

Interviewers use this question to quickly assess whether a candidate has the foundational knowledge required for TypeScript development. It reveals whether you understand the building blocks that more complex concepts rely on.

Answer

extends is used for inheritance — a class or interface inheriting from another class or interface. A class that extends another class inherits all its properties and methods. A child class can override parent methods with super for calling the parent implementation. TypeScript only supports single class inheritance (one extends). implements is used to declare that a class satisfies the contract of one or more interfaces or abstract classes, without inheriting their implementation. A class can implements multiple interfaces (comma-separated). implements only performs a compile-time shape check — it does not inherit any code. Example: class Dog extends Animal implements Pet, Trainable { ... }. Key differences: extends gives you the implementation (actual code); implements only guarantees the shape (structural contract). Interfaces can also extend other interfaces (even multiple ones): interface Admin extends User, Logger { ... }.

Pro Tip

This topic has TypeScript-specific nuances that differ from general programming. Highlighting those nuances in your answer shows expertise rather than generic knowledge.