After this lesson, you will be able to: Decide between interface and type alias; understand declaration merging and extension.
One of TS's daily decisions. The honest answer: mostly equivalent; small differences matter at scale.
`type` = type alias. Can represent ANYTHING (primitives, unions, intersections, computed types). `interface` = object shape only. Can be extended + augmented across files (declaration merging). Most teams use either; consistency matters more than choice.
Practical rules.
// Object shape that might be extended, interfaceinterface User {id: string;name: string;}interface AdminUser extends User {permissions: string[];}// Anything else, type aliastype Id = string | number;type Status = "active" | "closed";type Tuple = [string, number];type Callback = (x: string) => void;// Union of objects, must be `type`type Result = { ok: true; data: User } | { ok: false; error: string };// Both can describe object shape, these are equivalent in practice:type U1 = { name: string };interface U2 { name: string }
Sometimes useful; usually confusing.
// Augment a third-party type, common with React, Expressdeclare module "express-serve-static-core" {interface Request {user?: { id: string };}}// Now `req.user` is typed everywhere.// Same pattern doesn't work with type aliases.
Mixing both in one codebase without convention. Pick one default; document. Using interface for non-objects. Errors. Using type when you need declaration merging (rare). Long Pick/Omit chains when extends would read better.
Pick the difference.
Sign in and purchase access to unlock this lesson.