What s the difference between class and interface in TypeScript When do you use them

0 votes

I've got a login page that uses username and password in TypeScript.

export interface UserLogin {
  email: string;
  password: string;
}
//OR
export class UserLogin {
  email: string;
  password: string;
}

How do you know when to use what?

May 30, 2022 in TypeSript by Logan
• 2,140 points
372 views

1 answer to this question.

0 votes

A class is a blueprint of how objects are supposed to be implemented, whereas interfaces are used only for type-checking.

In your case, it would be right to use an interface for UserLogin.

answered May 31, 2022 by Nina
• 3,060 points

Related Questions In TypeSript

0 votes
0 answers

In typescript, why do the | and & operators flip their meaning when used on function types?

In this code, example1 and example2 are confusing me: type F1 = ...READ MORE

Jul 13, 2022 in TypeSript by Logan
• 2,140 points
295 views
0 votes
1 answer

How do you typecast in TypeScript?

Casting: return this.createMarkerStyle(<MarkerSymbolInfo> symbolInfo); Or Casting compatible with tsx mode: return ...READ MORE

answered Jun 1, 2022 in TypeSript by Nina
• 3,060 points
368 views
0 votes
1 answer

What does the ! (exclamation mark) do in TypeScript?

The exclamation mark is called the non-null ...READ MORE

answered Jun 1, 2022 in TypeSript by Nina
• 3,060 points
920 views
0 votes
1 answer

What does the @ (at sign) sign do in TypeScript?

The big news this week is the ...READ MORE

answered Jun 10, 2022 in TypeSript by Nina
• 3,060 points
584 views
0 votes
1 answer

Interface type check with Typescript

You can achieve what you want without ...READ MORE

answered May 31, 2022 in TypeSript by Nina
• 3,060 points
5,012 views
0 votes
1 answer

How to declare and initialize a Dictionary in Typescript

Apparently this doesn't work when passing the ...READ MORE

answered May 31, 2022 in TypeSript by Nina
• 3,060 points
5,454 views
0 votes
1 answer

TypeScript: Class Constructor type

class Zoo<T extends Animal> { ...READ MORE

answered Jun 8, 2022 in TypeSript by Nina
• 3,060 points
2,638 views
0 votes
1 answer

Difference between interfaces and classes in Typescript

Interfaces Describe how an object should look Exists compile ...READ MORE

answered Jun 15, 2022 in TypeSript by Nina
• 3,060 points
204 views
0 votes
1 answer

What is TypeScript and why would I use it in place of JavaScript?

TypeScript is a superset of JavaScript which primarily ...READ MORE

answered May 31, 2022 in TypeSript by Nina
• 3,060 points
302 views
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP