Reusable data contracts
Share one object shape across function parameters, return values, and variables.
TypeScript · Type Alias
A type alias names a TypeScript type, commonly an object shape with typed properties. It improves reuse and readability without creating a distinct runtime or nominal type.
A type alias gives a name to a type, including an object type described by named properties and their types. The alias is only another name for that type, so using it is equivalent to writing the underlying structure directly; aliases can also be generic and can represent unions, primitives, and other types.
type Name = {
property: Type;
optionalProperty?: Type;
};type User = {
id: number;
name: string;
email?: string;
};
function greet(user: User): string {
return `Hello, ${user.name}`;
}
console.log(greet({ id: 1, name: "Ada" }));Defines a reusable object shape with a required numeric id, required name, and optional email, then uses it as a function parameter.
Share one object shape across function parameters, return values, and variables.
Model containers whose contents vary while preserving their specific type.
Describe unions, tuples, primitives, or helper types that interfaces cannot express directly.
interfacegeneric typesobject typesunion types