While working with the "Tour of Heroes" tutorial on the Angular website I found the following syntax (shortly):
class Hero {
id: number,
name: string,
}
const aHero: Hero = {
id: 1,
name: 'Superman'
}
console.log(aHero instanceof Hero); //false
What would be the point in doing this? when if I check the type of "aHero", it is only a common object and not a "Hero" type. Would it be better just initializing an object with a constructor?:
class Hero {
constructor(id: number, name: string) {}
}
Heroshould be aninterface.interfacevsclass