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 in TypeSript by Logan
• 2,140 points
29 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 by Nina
• 3,020 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 in TypeSript by Logan
• 2,140 points
25 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 in TypeSript by Nina
• 3,020 points
29 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 in TypeSript by Nina
• 3,020 points
132 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 in TypeSript by Nina
• 3,020 points
25 views
0 votes
1 answer

Interface type check with Typescript

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

answered May 31 in TypeSript by Nina
• 3,020 points
253 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 in TypeSript by Nina
• 3,020 points
222 views
0 votes
1 answer

TypeScript: Class Constructor type

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

answered Jun 8 in TypeSript by Nina
• 3,020 points
58 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 in TypeSript by Nina
• 3,020 points
14 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 in TypeSript by Nina
• 3,020 points
13 views
webinar REGISTER FOR FREE WEBINAR X
Send OTP
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP