You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Also in the example file hero.model.ts it's using class:
export class Hero {
id: number;
name: string;
}
I think in this case better use interface instead of class when you it's just shape of the model? As I think typescript best practice is that in this case. Unlike classes, interfaces are completely removed during compilation and so they will not add any unnecessary bloat to our final JavaScript code.
Any reason to use class instead of interface in this case?? Or it's better to use interface in this case?
The text was updated successfully, but these errors were encountered:
I also found that interfaces are better. Especially when you start to work with state managers, you get some problems when trying to save class objects to the state.
I'm glad this issue so recent, as I have the same question. In @bampakoa's case, I don't believe you'd need to instantiate the Hero class. If you had an Interface, you could simply do
const stubHero: Hero = {
id: 1,
name: 'My hero'
}
I see the value in classes when dealing with methods and actual implementations. Though I think I'd prefer interfaces when modeling data as we're talking about here. Are we missing something as to why the guide suggests otherwise?
In style guid, it says consider use class instead of interface
https://angular.io/guide/styleguide#interfaces
Also in the example file hero.model.ts it's using class:
export class Hero {
id: number;
name: string;
}
I think in this case better use interface instead of class when you it's just shape of the model? As I think typescript best practice is that in this case. Unlike classes, interfaces are completely removed during compilation and so they will not add any unnecessary bloat to our final JavaScript code.
Any reason to use class instead of interface in this case?? Or it's better to use interface in this case?
The text was updated successfully, but these errors were encountered: