CodesJava

Easy learning with example program codes

typescript interface inheritance tutorial


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.

TypeScript provides the facility of inheritance between interfaces i.e. an interface can inherit other interface. We have to use extends keyword to implement inheritance among interfaces.

Syntax:

ChildInterfaceName extends SuperInterfaceName

Example:

interface Person { 
   age:number;
   name:string;
} 
 
interface Employee extends Person { 
   empId:string; 
} 
 
var engineer = <Employee>{}; 
engineer.age = 30; 
engineer.name = "Jai";
engineer.empId = "EMP024";
console.log("Name:  "+engineer.name);
console.log("Age:  "+engineer.age);
console.log("Emp Id:  "+engineer.empId);

Try it:

JS Bin on jsbin.com

Please follow and like us:


Copyright © 2019 CodesJava DMCA.com Protection Status SiteMap Reference: Java Wiki