0 votes
in TypeScript - JavaScript's Superset by
What do you mean by interfaces? Explain them with reference to Typescript.

1 Answer

0 votes
by

An Interface is a structure which acts as a contract in our application. It defines the syntax for classes to follow, it means a class that implements an interface is bound to implement all its members. It cannot be instantiated but can be referenced by the class object that implements it. The TypeScript compiler uses interface for type-checking (also known as "duck typing" or "structural subtyping") whether the object has a specific structure or not.

Syntax:

interface interface_name {    

          // variables' declaration    

          // methods' declaration    

}    

The interface just declares the methods and fields. It cannot be used to build anything. Interfaces need not be converted to JavaScript for execution. They have zero runtime JavaScript impact. Thus, their only purpose is to help in the development stage.

Related questions

0 votes
asked Jan 27, 2020 in TypeScript - JavaScript's Superset by AdilsonLima
+2 votes
asked Jun 21, 2021 in Mean Stack by SakshiSharma
...