Ad space (banner)
Lesson 14 / 20

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.

๐Ÿ“– Reference code
โœ๏ธ Your code
Type your code, then press "Run"

๐Ÿงช 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).

Ad space (banner)
Ad space (in-article)