I'm just checking out Typescript by reading the 5 minute tutorial here. I am an experienced programmer but I am having problems understanding the Classes section. The following code is shown there:
class Student {
fullName: string;
constructor(public firstName: string, public middleInitial: string, public lastName: string) {
this.fullName = firstName + " " + middleInitial + " " + lastName;
}
}
interface Person {
firstName: string;
lastName: string;
}
function greeter(person : Person) {
return "Hello, " + person.firstName + " " + person.lastName;
}
let user = new Student("Jane", "M.", "User");
document.body.innerHTML = greeter(user);
I understand the class and the interface definitions, but I do not get how Student is able to implement Person, as Person requires two string variables called firstName and lastName but Student only has one string variable called fullName. I see that the Student constructor includes the missing variables, but based in what I know about other languages, those are private variables to the constructor, whose contents only survive thru the fullName assignment. How come the greeter has access to the Student first and last name?