My understanding of interfaces in Typescript is that they work similar to interfaces in C#. Meaning, as long as your object implements the properties and methods defined in the interface, you are free to add additional properties in the object.
However, when I type this program into the Typescript Playground, I get an error:
module myTestDemo {
interface Person {
name: string;
age?: number;
}
var p: Person = {
favoriteMovie: 'Back to the Future',
name: 'Joe',
age: 40
};
}
It does not like the line favoriteMovie: 'Back to the Future'. It gives me an error:
'favoriteMovie' does not exist in type 'Person'.
Am I doing something wrong or am I wrong on understanding that objects cannot have additional properties when inheriting an interface?