Difference Between implements and extends in TypeScript
·
1 min read
·
154
Words
·
-Views
-Comments
Understanding
implements
vs.extends
helps you choose the right composition pattern in TypeScript.
Definitions
implements
“Implement” a contract. A class implements an interface (or another class) by providing all required members. It can override methods/properties and add new ones.
extends
“Inherit” behavior. A class or interface extends another class/interface, inheriting members. Properties are inherited; methods can be overridden.
Key Rules in TypeScript
- Only classes use
implements
(classes can implement interfaces or classes). - Interfaces can extend interfaces or classes.
- Classes can only extend classes (not interfaces).
- Multiple inheritance/implementation is allowed.
Java Comparison
In Java:
- Same as TypeScript: classes implement interfaces and extend classes. Multiple inheritance via interfaces is allowed.
- Difference: interfaces can’t extend classes—only other interfaces.
Takeaway
This is just a starting point; real-world use comes from practice.