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

Basic Type Alias Syntax

Define a type alias with type Name = Type; then use Name anywhere the original type would work.

Basic Type Alias Syntax

You'll learn how to create reusable type names with the type keyword, making complex types easier to read and maintain.


The Problem Type Aliases Solve

Imagine repeatedly writing { id: number; name: string; email: string } throughout your code. It's tedious, error-prone, and hard to update. Type aliases let you give a name to any type, then reuse that name everywhere.


Creating a Type Alias

The syntax is straightforward:

type Name = Type;

Here's a simple example:

type UserID = number;
type Email = string;

Now UserID and Email are just aliases for number and string. You use them exactly where you'd use the original types:

let currentUser: UserID = 42;
let contact: Email = "user@example.com";

Type Aliases for Complex Types

Type aliases shine with object types:

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

function greetUser(user: User): void {
  console.log(`Hello, ${user.name}!`);
}

const newUser: User = {
  id: 1,
  name: "Alice",
  email: "alice@example.com"
};

greetUser(newUser);

The alias User is now a named reference to that object structure. You can use it for parameters, return types, and variable annotations.


Why This Matters

Type aliases act like nicknames for types. They don't create new types—UserID is still just number—but they make your code self-documenting and centralize type definitions. Change the alias once, and every usage updates automatically.


Key Takeaway: Use type AliasName = SomeType; to give any type a reusable name, then use AliasName anywhere the original type would work—making your code cleaner and easier to maintain.