Interfaces

Interfaces are contracts that our code adheres too. It's an agreement that data structures must follow. This helps every data/logic implementing an interface stay safe from improper or non-matching types. It also validates the types and availability of values passed in.

In TypeScript, interfaces are used for the following:

  1. Creating types for JavaScript objects.
  2. Setting up contracts for classes to adhere to.

We will discuss how interfaces are applied in the scenarios we just listed.

Get TypeScript 2.x for Angular Developers now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.