【发布时间】:2021-11-01 04:22:55
【问题描述】:
我正在尝试从extended 类打印name。但收到错误消息:Property 'name' does not exist on type 'Employee'.
class Person {
#name:string;
getName(){
return this.#name;
}
constructor(name:string){
this.#name = name;
}
}
class Employee extends Person {
#salary:number;
constructor(name:string, salary:number = 0){
super(name);
this.#salary = salary;
}
async giveRaise(raise:number):Promise<void> {
this.#salary += raise;
await this.#storySalary;
}
pay():void {
console.log(`¤ ${this.#salary} is paid to ${this.name}.`);
}
async #storySalary():Promise<void> {
console.log(`Salary ¤ ${this.#salary} is stored for ${this.name}`);
}
}
const NewEmployee = new Employee('Sha', 300);
console.log(NewEmployee.getName(), NewEmployee.pay())
【问题讨论】:
标签: typescript typescript-class