Depth of the inheritance tree (DIT)

We can also declare a new class that inherits from a class, which is already inheriting from another class. In the following code snippet, we declare a class called SchoolPrincipal that extends the Teacher class, which extends the Person class:

class SchoolPrincipal extends Teacher { 
    public manageTeachers() { 
        return console.log( 
            `We need to help our students!` 
        ); 
    } 
} 

If we create an instance of the SchoolPrincipal class, we will be able to access all the properties and methods from its parent classes (SchoolPrincipal, Teacher, and Person):

const principal = new SchoolPrincipal( "Remo", "Jansen", "remo.jansen@wolksoftware.com" ); principal.greet(); // "Hi!" principal.teach(); // "Welcome to class!" principal.manageTeachers(); ...

Get Learning TypeScript 2.x - Second Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.