Exploring Typescript for the first time on Codepen.io has left me puzzled. I'm unsure why, despite defining the function signature and return type with an interface, I am able to return a different type without encountering any errors.
Is there something that I am overlooking?
Here's a snippet of the code:
interface IPerson {
getFullName: () => void;
}
class Person implements IPerson{
constructor(
public name: string,
public surname: string
){}
getFullName() {
return this.name + ' ' + this.surname;
}
}
let p = new Person('John','Doe');
console.log(p.getFullName());
Outcome:
John Doe
Dilemma: Why does it display 'John Doe' (a string) even though I specified a void return type?