I am creating a person
interface and created a method greeter
that takes in a person
and prints its first and last name. Then I created a class student
with a firstname and last name. Created an object of student
and passed to greeter
function and it works.
class Student{
fullName: string;
constructor(public firstName: string, public middleName: string ,public lastName: string)
{
this.fullName=firstName+" "+ middleName+" "+lastName;
}
}
interface Person {
firstName: string;
lastName: string;
}
function greeter(person: Person) {
return "Hello, " + person.firstName + " " + person.lastName;
}
let user =new Student("jane","doe","user");
document.body.textContent = greeter(user);
It should give an error
expected a person but got a student
but actually it prints fine.