Interfaces and type aliases both describe shapes, but each shines in different spots. **Interfaces** • Mergeable (declaration merging) • Great for OO contracts and public APIs • Extends using 'extends' **Types** • More flexible: unions, primitives, tuples, mapped types • Compose using '&' • Cannot merge, but work well for computed types Use interfaces for extensible object contracts; use types for unions/tuples/utility-based transforms.
interface Name { ... } | type Name = { ... }// INTERFACE
interface User {
name: string;
age: number;
}
interface User { // declaration merge
email: string;
}
// TYPE ALIAS
type Product = {
id: number;
title: string;
};
// EXTENDING
interface Admin extends User {
role: string;
}
type SuperAdmin = User & { permissions: string[] };
// UNION (types only)
type Status = "pending" | "approved" | "rejected";
// MAPPED TYPE (types only)
type Readonly<T> = { readonly [K in keyof T]: T[K] };Understanding Interfaces vs Types is fundamental to mastering TypeScript. Practice with the examples above and experiment with variations to solidify your knowledge.