Typescript interface

Dictionary meaning of interface:

A point where two systems, subjects, organizations, etc., meet and interact.

TypeScript interface:

An interface is declared with interface keyword. It is a way of implementing 100% abstraction. It only contains the declaration of the members. Interface forms a contract with your class that force your class to have all methods defined by the interface must appear in the class.

Syntax:

interface interface_name { 
}

Example:

interface IPerson { 
   firstName:string, 
   lastName:string, 
   sayHi: ()=>string 
} 

var customer:IPerson = { 
   firstName:"Ajay",
   lastName:"Laddha", 
   sayHi: ():string =>{return "Hi"} 
} 

console.log("Customer Object Details: ");
console.log(customer.sayHi()); 
console.log(customer.firstName); 
console.log(customer.lastName); 
 

var employee:IPerson = { 
   firstName:"Vikas",
   lastName:"Jainer", 
   sayHi: ():string =>{return "Hello"} 
} 
  
console.log("Employee  Object Details: ");
console.log(employee.sayHi());
console.log(employee.firstName);
console.log(employee.lastName);