Inheritance
Inheritance is one of the features of object-oriented programming, and TypeScript allows us to use this feature in writing code for JavaScript. Inheritance is a behavior of extending an existing class with additional features to create subclasses. The advantage of inheritance is code reuse; we can have common properties and methods defined in the parent class and have child classes inherit those properties and methods. We can then add specific functionalities to them.
To create a child class, TypeScript defines a keyword, extends, which is added to the child class followed by the name of the parent class.
The following is the example of implementing inheritance:
As we can see on line number 9, we created a new class, TypeScript ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access