Skip to content

Interface

In one line

An interface is a TypeScript construct that defines the shape of an object — which properties it has and their types — without containing any implementation code.

In simple words

An interface is a contract for objects. It describes what properties an object should have and what types those properties should be. Interfaces are compile-time only — they are erased when TypeScript compiles to JavaScript.

Interfaces are commonly used to type function parameters, API responses, and class shapes. They support optional properties (with ?), readonly properties, and extension (with extends).

A unique feature of interfaces is declaration merging: if you declare two interfaces with the same name, TypeScript combines them into one. This is useful for extending existing types, including built-in ones like Window.

Example

typescript
interface User {
  id: number;
  name: string;
  email?: string; // optional
}

const user: User = { id: 1, name: "Alice" };

The User interface defines the shape of user objects. The email property is optional.

Common confusions

  • Confused with: type alias

    The difference: Interfaces support declaration merging and 'extends'; type aliases support unions, intersections, and tuples. For object shapes, either works.

Related terms

Decode error messages

Plain-English explanations of common errors — what they mean, why they happen, and how to fix them.

View errors

← Back to glossary