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
• 1,580 points
17 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
• 2,900 points

Related Questions In TypeSript

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
• 2,900 points
18 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
• 2,900 points
52 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
• 2,900 points
9 views
0 votes
1 answer

How do I extend a TypeScript class definition in a separate definition file?

If you don't have control over the ...READ MORE

answered Jun 10 in TypeSript by Nina
• 2,900 points
15 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
• 2,900 points
43 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
• 2,900 points
43 views
0 votes
1 answer

TypeScript: Class Constructor type

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

answered Jun 8 in TypeSript by Nina
• 2,900 points
15 views
0 votes
2 answers

How can I convert a String variable to a primitive int in Java

 Here are two ways illustrating this: Integer x ...READ MORE

answered Aug 20, 2019 in Java by Sirajul
• 59,170 points
1,056 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
• 2,900 points
7 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
• 2,900 points
8 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