What is the difference between extends and implements in TypeScript?
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 { ... }.