interface Person {
name: string;
birthDate: Date;
}
class Patient implements Person {
name: string = 'patientName';
birthDate: Date;
constructor(name: string, birthDate: Date) {
this.name = name;
this.birthDate = birthDate;
}
getName(): string {
return this.name;
}
getBirthDate(): Date {
return this.birthDate;
}
}
const name: string = "John Smith";
const birthDate: Date = new Date('01-01-1970');
const isNewPatient: boolean = true;
const patient: Patient = new Patient(name, birthDate);
let age: number = 30;
const isMale: boolean = true;
const favoriteFruits: string[] = ['apple', 'banana', 'orange'];
const patientData: { name: string, birthDate: Date, isNewPatient: boolean } = {
name,
birthDate,
isNewPatient,
};
if (isNewPatient) {
console.log("Is new patient");
} else {
console.log("Is returning patient");
}
for (let fruit of favoriteFruits) {
console.log(fruit);
}
function addNumbers(x: number, y: number): number {
return x + y;
}
try {
const patient = new Patient(name, birthDate);
patient.name = '';
} catch (e) {
console.log('Error: ' + e.message);
}