TypeScript classes let you create objects with properties and methods, similar to classes in other OOP languages like C# and Java.
this keyword refers to the instance of that class.
class keyword defines a new classconstructor() initializes the class when calledthis.property to reference instance properties
class Admin extends User {
role: string;
constructor(name: string, role: string) {
super(name);
this.role = role;
}
showRole(): string {
return this.name + " is an " + this.role;
}
}
const admin1 = new Admin("Jamie", "Administrator");
console.log(admin1.showRole());
extends to create a child class, and call the parent constructor with super().