AI Hints
Home›TypeScript Tutorial›Aliases and Interfaces
TypeScript · Lesson 23 of 120

Interfaces

Describe objects.

⏱ 2 min read▶ Video at 18:29🎓 Free
Watch this lesson in the TypeScript courseWatch on YouTube ↗Full TypeScript course

Interfaces are another way to name an object type. They look very similar to aliases, without the equals sign. Many teams use them for object shapes.

Interfaces
From the video: Interfaces
  • Another way
  • No equals sign
  • Object shapes

A Customer interface

Interface Customer describes a customer, with an optional phone number. Welcome takes any customer. Run it.

app.tstypescript
interface Customer {
  name: string;
  email: string;
  phone?: string;
}

function welcome(c: Customer) {
  return `Welcome, ${c.name}! We'll email ${c.email}.`;
}

console.log(welcome({ name: "Priya", email: "priya@example.com" }));
Output
Welcome, Priya! We'll email priya@example.com.

Summary

Interfaces describe object shapes, just like aliases. Next, how to choose between them.

Key takeaways
  • interface Customer
  • Optional phone
  • Same checks
Next up: Aliases or Interfaces — how to choose