TypeScript Interface Vs Class

We have covered typescript interface and class in our previous tutorials.

Lets have a closer look at their differences:

Parameter TypeScript Class TypeScript Interface
Definition TypeScript Class is a template which holds methods,variables and provides a skeleton to object. TypeScript Interface is a blueprint which will tell a deriving class what to implement.
Syntax class <className>{
interface <iName>{
Practical Usage To design a skeleton of modules functionality wise To hide a complexity from external accessing resource and securing core logic
Instantiable We can Instantiate class using its object We can not instantiate interface
Inheritance Class supports inheritance by extending other class Supports inheritance but can not implement other interfaces
Functions Class can have functions and function has complete definition Interface can have function but it can not define it
Constructor Class can have constructor NA
Access Specifiers Class can public, private, protected Interface uses only public access specifier.

Leave a Reply

Your email address will not be published. Required fields are marked *