Lesson 18 of 56 · Typescript
Class Inheritance & Abstract Classes
Duration: 20 minutes
Inheritance
class Employee extends Person {
private employeeId: string;
constructor(name: string, ssn: string, birthYear: number, employeeId: string) {
super(name, ssn, birthYear);
this.employeeId = employeeId;
}
getId() { return this.employeeId; }
}
Abstract Classes
abstract class Shape {
abstract area(): number; // must be implemented by subclasses
}
class Circle extends Shape {
constructor(public radius: number) { super(); }
area() { return Math.PI * this.radius ** 2; }
}
instanceof Checks
function isShape(x: any): x is Shape {
return x instanceof Shape;
}