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

TypeScript · Const

interface

An interface names an object type and describes its required or optional members. TypeScript checks interface compatibility structurally, and interfaces can be extended or reopened.

How it works

An interface gives a reusable name to an object’s required and optional members. TypeScript checks values structurally, so an object is accepted when it has the required properties with compatible types; interfaces can also be extended, implemented by classes, and reopened for declaration merging.

Syntax

interface InterfaceName extends BaseInterface {
  property: Type;
  optionalProperty?: Type;
  readonly readOnlyProperty: Type;
}

Parameters

NameTypeDescription
membersobject properties and/or call signaturesThe interface declaration itself has no runtime parameters; its members describe the properties and callable signatures expected by the object shape.

Returns

An interface declaration produces a compile-time object type and no runtime value.

Key points

  • Interfaces participate in structural typing: compatibility depends on the required shape rather than the declared name.
  • Use an interface to give a reusable name to an object contract.
  • Extra properties are generally allowed when values come from variables, while required properties must exist with compatible types.
  • An interface can describe properties, optional members, readonly members, index signatures, and callable shapes.
  • A call signature lets an interface describe a callable function shape.

Common mistakes

  • Unlike a type alias, an interface can be reopened and augmented with additional properties.
  • An interface is for object shapes; use a type alias when you need to name a primitive or another non-object type.
  • Property declaration order does not affect compatibility.

Example: Describing and using an object shape

interface User {
  readonly id: number;
  name: string;
  email?: string;
}

function greet(user: User): string {
  return `Hello, ${user.name}`;
}

const user: User = { id: 1, name: "Ada" };
console.log(greet(user));

This runnable example declares an object shape, uses an optional property, prevents reassignment of an identifier, and applies the interface to a function parameter.

When to use it

Shared object contracts

Define shared request, response, configuration, or domain-object shapes across modules.

Function boundaries

Annotate function parameters and return values with a stable object shape.

Class contracts

Require classes to provide a defined public API.

Extensible APIs

Extend or augment an existing object shape across declarations.

  • type alias
  • extends
  • implements
  • declaration merging
  • structural typing
  • call signature
  • readonly
  • optional properties

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