November 2019
Beginner
804 pages
20h 1m
English
The last point that we need to cover for classes is indeed inheritance. As you might guess, TypeScript does indeed support it.
In the following code snippet, we are defining an abstract Shape class:
abstract class Shape {
constructor(private readonly _shapeName: string) {
this.displayInformation();
}
abstract displayArea(): void;
abstract displayPerimeter(): void;
protected get shapeName(): string {
return this._shapeName
}
public displayInformation(): void {
console.log(`This shape is a ${this._shapeName}`);
}
public doSomething(): void {
console.log("Not interesting");
}
}
And here, we create a Square class extending the abstract base class:
class Square extends Shape { constructor(private _width: number) { super("Square"); ...Read now
Unlock full access