December 2017
Beginner
372 pages
10h 32m
English
Once we have custom types defined using interfaces, the next step is to implement these interfaces using classes. TypeScript allows classes to implement interfaces using the implements keyword. When a class implements an interface, the TypeScript compiler checks to see whether all the properties and methods have been implemented in the class. This check helps in making sure that the class follows the contract defined by the interface.
The following example shows how we can implement an interface in a class:
interface IArticle{ author:string; title:string; formatdDate():void;}class Article implements IArticle{ author:string; title:string; formatdDate():void { // implementation detail }}let espn:IArticle = new Article(); ...
Read now
Unlock full access