TypeScript
Type Aliases vs Interfaces
•2 min read

Joshua R. Lehman
Author

Type Aliases vs Interfaces#
TypeScript provides two primary ways to define custom types: type aliases and interfaces. While they share similarities, understanding their differences and best use cases helps you write clearer and more maintainable code.
What Are Type Aliases and Interfaces?
- Type Aliases create a new name for any type, including primitives, unions, tuples, and object types.
type ID = string | number;
type Point = { x: number; y: number };- Interfaces define the shape of an object, specifying properties and their types.
interface Point {
x: number;
y: number;
}Key Differences
| Feature | Type Alias | Interface |
|---|---|---|
| Can represent primitives | Yes | No |
| Can represent unions | Yes | No |
| Can represent tuples | Yes | No |
| Can be extended | No (but can create intersections) | Yes (via extends) |
| Can be merged | No | Yes (declaration merging) |
| More flexible | Yes | More strict |
When to Use Type Aliases
- For union or tuple types.
- When you need to represent primitives or complex types.
- For composing types using intersections.
type Shape = Circle | Square;
type Coordinates = [number, number];When to Use Interfaces
- To define object shapes and contracts.
- When you want to take advantage of declaration merging.
- For extending existing interfaces.
interface Animal {
name: string;
}
interface Dog extends Animal {
breed: string;
}Composition Patterns
You can compose types and interfaces using intersections and extensions:
type A = { a: string };
type B = { b: number };
type C = A & B; // Intersection type
interface X {
x: boolean;
}
interface Y extends X {
y: string;
}Best Practices
- Use interfaces for public API object shapes.
- Use type aliases for unions, primitives, and tuples.
- Prefer interfaces when you need declaration merging or extension.
- Use intersections with type aliases for complex compositions.
Tip: Both interfaces and type aliases are powerful; choose based on your use case and team conventions.
Common Mistakes
- Trying to extend type aliases (use intersections instead).
- Overusing type aliases for object shapes where interfaces are clearer.
- Confusing declaration merging capabilities.
- Mixing interfaces and type aliases inconsistently.
Next Steps
Next, learn about object property modifiers like optional and readonly properties to further refine your type definitions.