Introduction to Inheritance

Learn about inheritance in TypeScript, including base and derived classes/interfaces, and how to implement it using the extend keyword.

Inheritance in TypeScript

Inheritance is another paradigm that is one of the cornerstones of object-oriented programming. Inheritance allows us to create an object based on another object, thereby inheriting all of its characteristics, including properties and functions. In TypeScript, inheritance can be used by classes and interfaces. We will take a closer look at inheritance and what it means for both classes and interfaces.

When discussing inheritance, it is important to clearly distinguish between the class that forms the basis of the inheritance structure and the class that is doing all of the inheriting.

We will use the terms “base class” or “base interface” to denote the class or interface that forms the base of the inheritance structure, and the terms “derived class”* or “derived interface” to denote the class or interface that is doing the inheriting.

TypeScript uses the extends keyword to implement inheritance, and we will look at practical examples of its usage next.

Interface inheritance

One interface can form the base interface for one or many other interfaces.

As an example of this, consider the following code:

Get hands-on with 1200+ tech skills courses.