Skip to main content

Interfaces

Interfaces describe the shape of objects and can be extended.

Defining Interfaces

interface User {
id: number;
name: string;
email?: string; // optional
}

function greet(user: User) {
return `Hello, ${user.name}`;
}

Extending Interfaces

interface Admin extends User {
permissions: string[];
}