+2 votes
in Mean Stack by
What is the difference between Classes and Interfaces in TypeScript?

1 Answer

0 votes
by

Classes and interfaces are structures that promote both object-oriented programming and also type-checking in TypeScript. While a class is a blueprint from which you can create a group of objects sharing the same configuration (properties and methods), an interface is a group of related properties and methods that describe an object. However, an interface does not provide implementation or initialization for the objects. 

Typically, a class defines what an object should look like and act like, and accordingly, it creates and implements a blueprint by initializing the class properties and defining methods. Classes are present throughout all the phases of a code. An interface, on the other hand, is a virtual structure that exists only within the context of TypeScript. The TypeScript compiler uses interfaces exclusively for type-checking. 

Related questions

0 votes
asked Mar 22, 2022 in TypeScript - JavaScript's Superset by sharadyadav1986
0 votes
0 votes
asked Mar 22, 2022 in TypeScript - JavaScript's Superset by sharadyadav1986
...