- 01Getting Started
- 02Your First Output (console.log)
- 03Variables and Type Annotations (number/string/boolean)
- 04Array Types
- 05Function Types (Parameters and Return Values)
- 06Optional Parameters and Default Parameters
- 07Interfaces (interface)
- 08Optional Properties (?)
- 09Type Aliases (type)
- 10Union Types
- 11Literal Types
- 12enum (Enumerated Types)
- 13Classes and Types
- 14Inheritance (extends) and Implementing an Interface (implements)
- 15Generics (<T>)
- 16Tuple Types
- 17The any and unknown Types
- 18Type Assertions (as)
- 19The readonly Modifier
- 20[Applied] Build a Mini Inventory Management System
Inheritance (extends) and Implementing an Interface (implements)
This lesson covers class inheritance (extends) and implementing an interface with implements. It's for anyone searching "TypeScript extends implements difference."
extends creates a new class that inherits an existing class's functionality. implements, on the other hand, makes a class promise to honor the "shape" defined by an interface.
The example inherits class Animal with class Dog extends Animal, and also guarantees "has a sound" by having it implements an interface Soundable.
A common early mistake is forgetting to call super() in the subclass. Skip the super() call, which runs the parent class's constructor, and you get a compile error.
In real projects, a common combination is inheriting a class with a shared trait, like "animal," while expressing a specific ability, like "makes a sound" or "can fly," through an interface.
๐งช This site can't compile or run TypeScript directly, so it checks on the spot whether what you typed matches the reference code (scoring happens entirely in your browser โ nothing is sent anywhere).
