This section lists additional type-compatibility rules and type guards that come with classes and class inheritage.
Descendant classes are subtypes of their superclasses, so one may write something such as the following:
let aTeacherOrPerson: Person = new Teacher("TypeScript", "Francesco", "Abbruzzese");
In ClassTest.ts, Teacher inherits from Person. On the other hand, one may use the instanceof type guard to discriminate among descendant classes:
let myCourse: string | null;
if (aTeacherOrPerson instanceof Teacher)
myCourse = aTeacherOrPerson.course;
else
myCourse = null;
Inside the if branch, aTeacherOrPerson is assumed to be of the Teacher type because of the new instanceof type guard. instanceof returns true if the object on its left is an instance of the class on its right, or an instance...