We're sorry but this app doesn't work properly without JavaScript enabled. Please enable it to continue.

This lesson's interactive features are locked, please to keep using them

Interfaces

Click to play video

As it turns out, there are two ways to define object types: the type keyword (as we've seen with type aliases) and interfaces:

type Superhero = {
  name: string;
  powers: string[];
  isAvenger: boolean;
};

interface Superhero {
  name: string;
  powers: string[];
  isAvenger: boolean;
}

I'm a huuuuge fan of having multiple ways to do the same things in a language... /s

In 9/10 scenarios, they work the same way, but there are a few key differences that we'll cover in this chapter. For now, just know that I recommend using type in most cases, but there are a few scenarios where interface is the better choice, which we'll talk about later.

Assignment

We need a way to get analytics on each of Support.ai's support sessions. Each session contains basic info about the session as well as the customer's feedback on the interaction.