Given this TypeScript class:
export class Person { public constructor (public firstName: string, public lastName: string) { } public fullName(): string { return `${this.firstName} ${this.lastName}`; } public WriteInfo() { console.log(this.fullName()); } } What is the proper way to override the constructor in a descendent class?
I have:
import { Person } from './class'; export class Employee extends Person { public constructor (afirstName: string, alastName: string, public Salary: number) { super(afirstName, alastName); } public WriteInfo() { let s: string = `${this.fullName()} makes this much: -- $${this.Salary}`; console.log(s); } } but I am not sure that is the correct declaration for the constructor, particularly with regard to the default properties.
Do the firstName and the lastName parameters of Employee have to be declared public as well? What I have works, but I just want to check to see if this is correct/accepted/proper/conventional.
publicin the super class no need for this, if it was not good, TS would hit you right into your face ;-) That's why it's there :-)