Type Aliases
Learn how to create reusable, named types with the type keyword.
Reading Time
12 min
Lesson
Lesson 8 of 30
What is a Type Alias?
A type alias gives a name to any type — a primitive, an object shape, a union, or anything else — so it can be reused instead of repeating the same definition everywhere.
A Basic Type Alias
type ID = string | number;
let userId: ID = 42;
let orderId: ID = "ORD-1001";Aliasing Object Shapes
Type aliases are commonly used to name the shape of an object, avoiding repetition across function signatures.
Object Shape Alias
type User = {
id: number;
name: string;
email: string;
};
function greetUser(user: User): string {
return `Hello, ${user.name}!`;
}Aliasing Function Types
A type alias can also describe the shape of a function — its parameter types and return type — useful for typing callbacks consistently.
Function Type Alias
type MathOperation = (a: number, b: number) => number;
const add: MathOperation = (a, b) => a + b;
const subtract: MathOperation = (a, b) => a - b;Composing Aliases
Type aliases can be built from other aliases, combined with unions and intersections, keeping complex types readable and DRY.
Composed Type Aliases
type Status = "pending" | "active" | "completed";
type Task = {
title: string;
status: Status;
};Type Aliases Don’t Create New Types
A type alias is just a name for an existing type — it doesn’t create a distinct new type the way a class does. Two aliases pointing at the same shape are fully interchangeable.
Best Practice
Name a type as soon as it’s used in more than one place, or once its inline definition becomes hard to read at a glance — clear names make signatures far easier to scan.