A type alias is just a name for a type. In simple language, instead of repeating { id: number; name: string } everywhere, we name it User once and reference it.
The basics
type ID = string | number;
type User = {
id: ID;
name: string;
email: string;
};
const u: User = { id: 1, name: "Manish", email: "x@y.com" };
That’s it. The type keyword followed by a name and an =. Anything to the right of = can be a type expression — primitives, objects, unions, tuples, functions, anything.
Aliasing primitives
Useful when a primitive carries domain meaning.
type Email = string;
type UserId = number;
type Timestamp = number;
function notify(to: Email, at: Timestamp): void { /* ... */ }
Note: this doesn’t make Email a distinct type from string — it’s just a label. Any string will work where Email is expected. For nominal typing (truly distinct types) we need a “branded type” pattern. That’s an advanced topic.
Aliasing function signatures
type Predicate<T> = (value: T) => boolean;
const isEven: Predicate<number> = (n) => n % 2 === 0;
const isShort: Predicate<string> = (s) => s.length < 5;
Aliasing unions
This is where aliases really pay off — naming a union makes it reusable and self-documenting.
type LoadState = "idle" | "loading" | "success" | "error";
function render(state: LoadState) { /* ... */ }
Aliasing tuples
type Point = [x: number, y: number];
type RGB = [number, number, number];
Aliases can reference each other
type ID = string | number;
type Entity = { id: ID; createdAt: number };
type User = Entity & { name: string };
type Post = Entity & { title: string; authorId: ID };
Generic type aliases
Aliases accept type parameters, just like functions accept value parameters.
type Result<T> = { ok: true; value: T } | { ok: false; error: string };
const r: Result<number> = { ok: true, value: 42 };
const e: Result<string> = { ok: false, error: "not found" };
Type alias vs interface (quick recap)
interfaceonly describes object shapes.typedescribes anything — objects, unions, primitives, tuples, function signatures.- Aliases can’t be redeclared/merged; interfaces can.
See the “Type vs Interface” note for the full comparison.
Naming conventions
A few common patterns teams use:
- PascalCase for type names (
User,OrderStatus). - No
Iprefix for interfaces (that’s a C# convention, not TS). Propssuffix for React component props (ButtonProps).Tprefix or just one letter for generics (T,K,V— orTItemif multiple).
Interview soundbite
“A type alias is a name for a type expression. It’s the simplest tool for reuse — define a shape once, use it everywhere. Unlike interfaces, aliases can name any type: unions, tuples, primitives, function signatures. They’re inert at runtime — purely a compile-time label.”