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

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

  • Import our interface named Security

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 Upgrade Your Skills Today!
Sign up now and have the latest tech tutorials delivered straight to your mailbox.

PLUS: Get exclusive member-only discounts (up to 80% OFF!!) on our top tech courses in Udemy!
We hate spam. Your email address will not be sold or shared with anyone else.