Наследование ААП класаў у TypeScript
Наследование класаў у TypeScript ажыццяўляецца звычайным чынам, гэтак жа, як і ў чыстым JavaScript.
Давайце паспрабуем. Хай у нас ёсць наступны клас:
class User {
name: string;
constructor(name: string) {
this.name = name;
}
}
Давайце ўспадкуем ад гэтага класа:
class Student extends User {
course: number;
constructor(name: string, course: number) {
super(name);
this.course = course;
}
}
Стварыце клас Employee, які
наследуе ад класа User.