Name complex types
Replace repeated unions, tuples, or object shapes with one readable name shared across APIs.
TypeScript · Type Alias
A type alias gives a reusable name to a type expression. Unlike a class or runtime value, it is erased during compilation and does not create a distinct type identity.
A type alias binds a name to an existing type expression. It can represent primitives, unions, tuples, object shapes, and generic compositions, so large codebases can give reusable names to complex types without introducing a distinct runtime or nominal type.
type Name<Parameters> = Type;type declaration introduces a reusable name for a type expression.type UserId = string;
function loadUser(id: UserId): User {
return { id, name: "Ada" };
}
interface User {
id: UserId;
name: string;
}
const user = loadUser("u-42");
console.log(user.name);The alias documents that user identifiers are strings while allowing the existing string type wherever UserId is used.
Replace repeated unions, tuples, or object shapes with one readable name shared across APIs.
Document the intended role of a primitive such as an identifier without adding runtime code.
Define reusable type-level utilities that transform or combine types through parameters.
A type alias gives another name to a type expression. It can name primitives, unions, tuples, object types, and other combinations, but it does not create a separate runtime type.
Follow-up: How would you make an identifier distinct from string? Use a branded or otherwise intersected type pattern rather than a plain alias, because a plain alias remains equivalent to string.
Use the type keyword followed by the alias name, optional type parameters, an equals sign, and the type expression. For example, type Result<T> = T | Error names a generic union.
Follow-up: What must a generic alias do with its type parameter? It should reference the parameter in the aliased expression, such as T in T | Error, so instantiation can substitute a concrete type.
Type aliases are more flexible when the named type is not an object shape: they can describe primitives, unions, tuples, and other types. Interfaces are another way to describe object-oriented contracts, but the page emphasizes the broader forms available to aliases.
Follow-up: Can an interface extend a primitive alias? No; an interface cannot add to a primitive alias such as type S = string.
interfaceunion typestuple typesgeneric types