November 2018
Beginner
502 pages
10h 22m
English
Classes can extend other classes. This is the same concept as interfaces extending other interfaces, which we covered in the Extending interfaces section. This is a way for class properties and methods to be shared with child classes.
As with interfaces, we use the extends keyword followed by the class we are extending. Let's look at an example:
class Product { name: string; unitPrice: number;}interface DiscountCode { code: string; percentage: number;}class ProductWithDiscountCodes extends Product { discountCodes: DiscountCode[];}
Read now
Unlock full access