Difference Between implements and extends in TypeScript

Clarifies how implements vs. extends behave in TypeScript and compares them with Java.

Jan 30, 2020 · 1 min read · 154 Words · -Views -Comments · Programming
TypeScript 🇨🇳 阅读中文版
Read with AI

Choose an AI assistant

ChatGPT Open in a new tab with the article link and prompt
Claude Copy the prompt, then open Claude

Open Claude
Trouble reading the article?

If the prompt is missing, copy the full prompt below into your AI assistant. If the AI cannot read the article, paste the visible passage you want to discuss and add your question.

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

  1. Only classes use implements (classes can implement interfaces or classes).
  2. Interfaces can extend interfaces or classes.
  3. Classes can only extend classes (not interfaces).
  4. Multiple inheritance/implementation is allowed.

diagram

Java Comparison

In Java:

  1. Same as TypeScript: classes implement interfaces and extend classes. Multiple inheritance via interfaces is allowed.
  2. Difference: interfaces can’t extend classes—only other interfaces.

java diagram

Takeaway

This is just a starting point; real-world use comes from practice.

References

Authors
Developer, digital product enthusiast, tinkerer, sharer, open source lover