Skip to content
masterclassBuddyTech Buzz5 fresh blogs · 5:00 AM IST

TypeScript · Type Alias

object

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.

How it works

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.

Syntax

type Name = {
  property: Type;
  optionalProperty?: Type;
};

Key points

  • Use the type declaration to assign a reusable name to an object shape or any other TypeScript type.
  • Object aliases describe properties inline, using either commas or semicolons between members.
  • Choose an alias when the reusable abstraction may need to express non-object types or generic helper types.

Common mistakes

  • A type alias does not create a nominal or distinct type; it only names the existing type.
  • Omitting a property type causes it to be inferred as any, so explicit property types are generally safer.

Example: Reusable object shape

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.

When to use it

Reusable data contracts

Share one object shape across function parameters, return values, and variables.

Generic object shapes

Model containers whose contents vary while preserving their specific type.

Composite type definitions

Describe unions, tuples, primitives, or helper types that interfaces cannot express directly.

  • interface
  • generic types
  • object types
  • union types

Source: TypeScript: Documentation - Object Types. Checked 2026-10-15.