Prev Next

Web / Typescript interview questions

Explain interface in typescript.

Interface is a structure that defines the contract/syntax for classes to follow. Classes that are derived from an interface must follow the structure.

An Interface can define properties, methods, and events. Interface only declare the members and deriving class define the members.

interface IEmployee{ 
   emplD: number,
   firstName: string, 
   lastName: string,
   department: string,
   calcGrossIncome: (number)=>number 
} 

TypeScript compiler uses interface for type check and does not convert interface to JavaScript. This is also referred as duck typing or sometimes structural subtyping.

More Related questions...

Show more question and Answers...


Comments & Discussions