Typescript Interface [Typescript Tutorial]

An Interface is a description that defines specific methods that implements a class. Again, open your integrated terminal then type ng g interface <interfaceName>

typescript interface

typescript interface

An Interface named Security is generated and ready for editing.

typescript interface

A sample interface

typescript interface

To use your interface, first you have to choose a class that will implement your interface. Let’s choose Bonds which we created earlier.  

typescript interface

 

  • Import our interface named Security

 

typescript interface

In the export class of Bonds, add implements Security. If you’ll notice, Bonds has two errors.

typescript interface

It says that property trade and fairValueCompute is missing in the type Bonds. What you need to do is add those into the Bonds class.

typescript interface

The error should be resolved and you should now be able to save your work.

Subscribe Now and Get our React Native Course for FREE!
Sign up now and have the latest tech tutorials delivered straight to your mailbox.

PLUS: Get FREE access to our React Native course, coming soon on Udemy!
We hate spam. Your email address will not be sold or shared with anyone else.