Error Messages: Interfaces Show Names, Types Show Shapes
You'll learn: How TypeScript displays interfaces and type aliases differently in error messages, affecting readability and debugging.
The Error Message Difference
When TypeScript detects a type mismatch, interfaces appear by their declared name in error messages, while type aliases often expand to show their full structure. This might seem like a small detail, but it significantly impacts how easy errors are to understand.
Think of it like a map reference: an interface says "you're at the Library" (a named landmark), while a type alias might say "you're at the two-story brick building with green shutters on Oak Street" (the full description). Both are accurate, but one is far quicker to read.
Why This Happens
TypeScript's compiler tries to help you by showing exactly what shape it expected. For interfaces, the name itself is meaningful — it represents a contract. For type aliases, TypeScript sometimes expands the structure to show you precisely what was expected, especially for complex types.
interface User {
name: string;
age: number;
}
type Person = {
name: string;
age: number;
};
// Error with interface: "Type 'string' is not assignable to type 'User'"
const userTest: User = "wrong";
// Error with type: "Type 'string' is not assignable to type '{ name: string; age: number; }'"
const personTest: Person = "wrong";
Notice how the interface error mentions User by name, while the type alias error shows the entire object shape. With larger objects, type alias errors can become walls of text.
Key Takeaway: Interfaces produce cleaner, name-based error messages, while type aliases often expand to show full shapes — making interfaces easier to debug when dealing with complex object structures.