Skip to content

Type Aliases in TypeScript

How to create named type aliases for primitives, unions, objects, and function signatures.

What you'll learn

  • How to define a type alias with the type keyword
  • The difference between type aliases and interfaces
  • Using aliases for union types and function signatures
  • When to choose a type alias over an interface

Concept

Creating Named Types

A type alias gives a name to any type using the type keyword: type ID = number | string;. Unlike interfaces, which only describe object shapes, type aliases can name primitives, unions, intersections, tuples, and function signatures. This makes them more flexible for non-object types. For example, type Callback = (error: Error | null, result?: any) => void names a common callback pattern.

Type Aliases vs Interfaces

Interfaces and type aliases are very similar for object types — both can describe object shapes, both can be extended (interfaces via extends, aliases via intersection &). The key differences: interfaces can be merged (re-declaration combines members), while type aliases cannot. Type aliases can express unions and primitives, while interfaces cannot. Use interfaces for object shapes that might be extended, and aliases for unions, primitives, and function types.

Practical Usage

Type aliases shine for naming union types (type Status = "active" | "inactive" | "pending"), tuple types (type Point = [number, number]), and function signatures (type Handler = (event: Event) => void). They make code self-documenting by giving meaningful names to complex types, and they are essential for building the advanced type patterns covered later in this course.

Example

              // Type alias for a union of string literals (string literal type).
type Status = "active" | "inactive" | "pending";

// Type alias for a tuple.
type Point = [number, number];

// Type alias for a function signature.
type Handler = (event: string) => void;

// Type alias for an object shape (similar to interface).
type User = {
  id: number;
  name: string;
  status: Status;
};

const user: User = { id: 1, name: "Alice", status: "active" };
const origin: Point = [0, 0];

const logHandler: Handler = (event) => console.log(event);
logHandler(user.status);
            

Type aliases name any type: unions, tuples, functions, and objects. Use them for non-object types and unions; use interfaces for extensible object shapes.

Try it

Common mistakes

The mistake

Using type alias when interface extension or merging is needed

The fix

Interfaces support declaration merging and extends. If you need to combine definitions across files, use an interface instead of a type alias.

The mistake

Thinking type and interface are completely interchangeable

The fix

They are nearly identical for objects, but only type aliases can express unions, primitives, and tuples. Choose based on what you are naming.

Practice Type Aliases in TypeScript

6 exercises

Practice Type Aliases in TypeScript

Look up unfamiliar terms

A beginner-friendly glossary explains jargon in plain English — variables, functions, DOM, Promise, and more.

View glossary

Build real projects

Apply what you learned by building guided projects with starter code and solutions.

View projects

Decode error messages

Plain-English explanations of common errors — what they mean, why they happen, and how to fix them.

View errors