Course contentsShow
← TypeScript
Lesson 357 of 1,7968. Interfaces vs Type AliasesFree lesson

Type Aliases vs Inline Types

Named type aliases improve readability and DRY; use them when a type appears multiple times or is conceptually important.

Type Aliases vs Inline Types

You'll learn: When to extract a type alias versus writing the same type inline, and why naming improves your code.

The DRY Principle Meets Types

Imagine writing out someone's full mailing address every time you need to reference it, versus saving it as "home address" once. Type aliases work the same way—they let you name and reuse a type structure instead of writing it out repeatedly.

Inline Types: Quick but Repetitive

You can write object types directly wherever you need them:

function createUser(user: { name: string; age: number; email: string }) {
  // ...
}

function updateUser(user: { name: string; age: number; email: string }) {
  // ...
}

const currentUser: { name: string; age: number; email: string } = {
  name: "Alice",
  age: 30,
  email: "alice@example.com"
};

This works, but it's repetitive and error-prone. What if you need to add a property? You'd have to update it in three places.

Type Aliases: Named and Reusable

Extract the type once with a meaningful name:

type User = {
  name: string;
  age: number;
  email: string;
};

function createUser(user: User) {
  // ...
}

function updateUser(user: User) {
  // ...
}

const currentUser: User = {
  name: "Alice",
  age: 30,
  email: "alice@example.com"
};

Now the concept of a "User" exists in your codebase. Changes happen in one place, and the intent is immediately clear.

When to Extract

  • Type appears multiple times: DRY principle applies
  • Type has conceptual meaning: "User", "Config", "Response" communicate intent
  • Type is complex: Nested objects or unions are easier to understand when named

Inline types are fine for one-off, simple structures that don't represent a meaningful domain concept.

Key Takeaway: Use type aliases when a type appears multiple times or represents an important concept—they improve readability, maintainability, and follow the DRY principle.