TypeScript Tutorial · TypeScript Basics · Lesson 7 of 25

TypeScript Interfaces

Describe object shapes with interface, extend them and compare with type aliases.

interface

An interface describes the shape of an object, much like an object type alias:

Example 1Try it yourself
interface User {
  id: number;
  name: string;
  email?: string;
  greet(): string;
}

const ada: User = {
  id: 1,
  name: "Ada",
  greet() {
    return `Hi, I'm ${this.name}`;
  },
};
console.log(ada.greet());

Output

Hi, I'm Ada

Extending interfaces

Interfaces can extend one or more others:

Example 2Try it yourself
interface Entity {
  id: number;
  createdAt: string;
}
interface Post extends Entity {
  title: string;
  tags: string[];
}

const post: Post = { id: 7, createdAt: "2026-10-12", title: "Learning TS", tags: ["ts", "js"] };
console.log(`${post.title} (#${post.id}) tagged ${post.tags.join(", ")}`);

Output

Learning TS (#7) tagged ts, js

interface or type?

Both work for object shapes. Differences:

  • type can also name unions, tuples, primitives and mapped types; interface describes only objects (and functions/classes).
  • Interfaces with the same name merge (declaration merging) — useful for extending library types.

A common convention: use interface for object shapes and public APIs, type for everything else. Consistency matters more than the choice.

Test yourself

Which keyword lets one interface build on another?

  1. implements
  2. extends
  3. includes
  4. inherits
Show answer

Answer: extends