100% Free Forever
AI-Powered Learning
Industry Expert Content
Certificates & Badges
Learn At Your Own Pace
TypeScript

Type Aliases in TypeScript

Use `type` to give a name to any type -- primitives, unions, tuples, function signatures, and more.

Type System BasicsIntermediate9 min readJul 8, 2026
Analogies

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

typescript
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

typescript
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

text
[ 'Review PR' ]

6. Key Takeaways

Practice what you learned

Was this page helpful?

Topics covered

#TypeScript#TypeScriptProgrammingStudyNotes#Programming#TypeAliasesInTypeScript#Type#Aliases#Syntax#Explanation#StudyNotes#SkillVeris