My situation involves a simple model class (not a component):
export class animalModel {
constructor(public name: string) { }
getName(): string {
return this.name.toUpperCase();
}
}
Now, I am attempting to use this model in a component as shown below:
pet: animalModel = {name: 'fluffy' };
However, upon compilation, I encounter the following error:
Type '{ name: string }' is not assignable to type 'animalModel'. Property 'getName' is missing in type '{ name: string }'
When I remove the getName function from the animalModel, it compiles without any issues. Why does it restrict me from adding a method?