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:
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:
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:
typecan also name unions, tuples, primitives and mapped types;interfacedescribes 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?
implementsextendsincludesinherits
Show answer
Answer: extends