Angular tutorial referencing the "hero class" - educational inq

12 views
Skip to first unread message

learningA

unread,
Oct 2, 2019, 12:51:57 PM10/2/19
to Angular and AngularJS discussion
Hello,

Going through several tutorials and came a cross the following examples "export class Hero" or "export interface User" it seems like its interchangeable pending who writes the tutorial. so the question is, does it matter which format I use?


Which is the correct format if not when should the difference be applied?

export  interface  User {
    email: string;
    password: string;
}

export class Hero {
  id: number;
  name: string;
}

Sander Elias

unread,
Oct 3, 2019, 1:51:27 AM10/3/19
to Angular and AngularJS discussion
Hi LearningA,

Not much of an Angular question, and more of a typescript one. 
Ok, an interface is a type, and only exists during developing time. This means that during runtime there is no cost left. No extra memory, and no unneeded initializations.
There is for cases like this, no upside in using a class.

Regards
Sander

Reply all
Reply to author
Forward
0 new messages