interface

Declares an object shape contract that can be implemented and extended.

Since TS 1.0 Spec ↗

Syntax

interface Name extends Base { members }

Examples

interface User {
  id: number;
  name: string;
  greet(): string;
}

const u: User = { id: 1, name: 'Ada', greet: () => 'hi' };
interface Animal { legs: number; }
interface Dog extends Animal { bark(): void; }

Notes

Interfaces describe object and function shapes. They support declaration merging: multiple declarations with the same name are combined. Prefer `interface` for public object contracts and `type` for unions, tuples, or computed types. A class can `implements` an interface.

See also