1. Introduction
A type alias creates a new name for a type using the type keyword. Unlike a variable, a type alias doesn't hold a runtime value -- it exists purely at compile time to make complex or repeated type expressions easier to read and reuse. Type aliases can refer to virtually any type: primitives, object shapes, unions, intersections, tuples, function signatures, and generics.
Cricket analogy: A type alias is like giving a shorthand nickname, say PowerplayOver, to a well-known but wordy situation description, it doesn't change the over itself, it just exists in the commentary box to make repeated references easier, since it holds no runtime value.
Type aliases are especially useful for naming union types (which interfaces cannot express directly), tuple types, and function type signatures, giving your codebase self-documenting, reusable type definitions instead of repeating the same inline type everywhere.
Cricket analogy: A type alias like type Result = Win | Loss | Tie | NoResult names a match-outcome union that an interface simply cannot express directly, giving commentary scripts a single reusable, self-documenting label instead of repeating the four options everywhere.
2. Syntax
type ID = string | number;
type Point = { x: number; y: number };
type Coordinates = [number, number];
type Callback = (message: string) => void;
let userId: ID = 101;
const origin: Point = { x: 0, y: 0 };
const pair: Coordinates = [10, 20];
const log: Callback = (msg) => console.log(msg);3. Explanation
A type alias can name literally any type expression, including primitives (type Age = number), unions (type Status = "idle" | "loading" | "done"), tuples (type RGB = [number, number, number]), and function types (type Handler = (event: Event) => void). This flexibility is the key difference from an interface, which is limited to describing the shape of objects (and function/constructor call signatures) -- interfaces cannot directly alias a union, a primitive, or a tuple the way type can.
Cricket analogy: A type alias can name a primitive like type OverCount = number, a tuple like type BattingPair = [string, string], or a union like type Format = T20 | ODI | Test, flexibility an interface lacks, since an interface can only describe an object's shape, not directly alias a union, primitive, or tuple.
Type aliases can also be generic, letting you parameterize the aliased type: type Box<T> = { value: T }. Two structurally identical types (an alias and an equivalent interface, or two different aliases with the same shape) are considered compatible by TypeScript's structural typing system -- the alias name itself has no effect on runtime behavior or assignability, it is purely a compile-time label.
Cricket analogy: A generic alias like type ScoreBox<T> = { value: T } is a reusable scoreboard template that works for runs, wickets, or overs alike, and a BattingStats alias built to the exact same shape as an interface of the same fields is treated as fully compatible by TypeScript's structural typing.
Gotcha: interface declarations can be reopened and merged (declaration merging) if declared multiple times with the same name in the same scope, but type aliases cannot -- redeclaring a type with the same name in the same scope is a compile error. Choose interface for extensible object shapes (e.g. library public APIs) and type for unions, tuples, and function signatures.
4. Example
type Status = "pending" | "active" | "closed";
type Task = {
id: number;
title: string;
status: Status;
};
type TaskFilter = (task: Task) => boolean;
const tasks: Task[] = [
{ id: 1, title: "Write report", status: "pending" },
{ id: 2, title: "Review PR", status: "active" },
{ id: 3, title: "Deploy", status: "closed" },
];
const isActive: TaskFilter = (task) => task.status === "active";
const activeTasks = tasks.filter(isActive);
console.log(activeTasks.map((t) => t.title));5. Output
[ 'Review PR' ]6. Key Takeaways
Practice what you learned
1. Which of the following can a `type` alias represent that a plain `interface` cannot directly express?
2. What happens if you declare `type Point = { x: number }` twice in the same scope?
3. Which type alias correctly represents a fixed-length tuple of two numbers?
4. Can a type alias be generic?
5. Two differently named type aliases with identical structure are assigned to each other. What happens?
Was this page helpful?
You May Also Like
interface vs type in TypeScript
Compare TypeScript's `interface` and `type` keywords — when each is preferable, and what each can and cannot express.
Union and Intersection Types in TypeScript
Combine types with `|` (union) and `&` (intersection) to model values that can be one of several shapes or must satisfy all of them.
Tuples in TypeScript
Fixed-length, ordered arrays where each position has its own known type — and the classic mutability gotcha to watch for.
Generics in TypeScript
Learn how TypeScript generics let you write reusable, type-safe code that works across many types without losing type information.
Related Reading
Related Study Notes in Programming
Browse all study notesApache Spark Study Notes
Programming · 30 topics
ProgrammingApache Flink Study Notes
Programming · 30 topics
ProgrammingHadoop Study Notes
Programming · 30 topics
ProgrammingSnowflake Study Notes
Programming · 30 topics
ProgrammingApache Airflow Study Notes
Programming · 30 topics
Programmingdbt (Data Build Tool) Study Notes
Programming · 30 topics