February 2019
Beginner
694 pages
18h 4m
English
Classes can also use inheritance in the same manner as interfaces. Using our definitions of the IBase and IDerivedFromBase interfaces, the following code shows an example of class inheritance:
class BaseClass implements IBase {
id: number | undefined;
}
class DerivedFromBaseClass
extends BaseClass
implements IDerivedFromBase {
name: string | undefined;
}
The first class, named BaseClass, implements the IBase interface, and as such, is only required to define a property of id, of type number or undefined. The second class, DerivedFromBaseClass, inherits from the BaseClass class (using the extends keyword), but also implements the IDerivedFromBase interface. As BaseClass already defines the id property required in the IDerivedFromBase ...
Read now
Unlock full access