Back

Interfaces

Interfaces define the shape of an object: what properties it must have and what types they should be. They're like a contract your data must follow.

interface User {
  name: string
  age: number
  email: string
  isAdmin?: boolean  // ? means optional
}

const user: User = {
  name: "Daniel",
  age: 20,
  email: "daniel@example.com"
  // isAdmin is optional, so we can skip it
}

function displayUser(user: User): void {
  console.log(`${user.name}: ${user.email}`)
}

Roadmap