Suggest an editImprove this articleRefine the answer for “Why are interfaces more often used for objects?”. Your changes go to moderation before they’re published.Approval requiredContentWhat you’re changing🇺🇸EN🇺🇦UAPreviewTitle (EN)Short answer (EN)**Interfaces** were originally created to **describe the shape of objects**: TypeScript was designed as a layer on top of JavaScript, where almost everything is an object (functions, classes, data, modules). **Key point:** an interface tells TypeScript that an object matching this contract must have these fields and types.Shown above the full answer for quick recall.Answer (EN)Image## 1. Interfaces were originally **created to describe the structure of objects** TypeScript was designed as a **layer on top of JavaScript**, where almost everything is an object: functions, classes, data, modules. That is why interfaces were originally meant to **describe the shape of these objects**. ```javascript interface User { id: number; name: string; isAdmin: boolean; } ``` > An interface tells TypeScript: > "An object that matches this contract must have these fields and types." --- ## 2. Interfaces are "contracts" for classes and modules An interface is ideal for **contracts**: it describes *what an object must contain*, but not *how it is built*. ```javascript interface Logger { log(message: string): void; } class ConsoleLogger implements Logger { log(message: string) { console.log(message); } } ``` > Interfaces create a "contract" between a class and external code: > the class **is required** to implement everything described in the interface. --- ## 3. Interfaces support **inheritance and extension** Interfaces can be extended (`extends`) and merged (merging), which is convenient specifically for **object structures** (DTOs, APIs, entities). ```javascript interface Entity { id: number; } interface User extends Entity { name: string; } interface Admin extends User { role: "admin"; } ``` > Such hierarchies are common in data models (for example, users, orders, products). > That is why interfaces are a natural choice for describing "object entities". --- ## 4. Interfaces can **merge automatically** (declaration merging) This is extremely useful when typing **libraries and APIs**. ```javascript interface User { id: number; } interface User { name: string; } const user: User = { id: 1, name: "Tim" }; // Both interfaces merged ``` > `type` cannot do this, it will produce an error on duplication. > That is why interfaces are more often used for **objects and extensible entities** (for example, `Express.Request`). --- ## 5. Interfaces are logically closer to "object thinking" TypeScript is a language where **typing and the object model go hand in hand**. An interface helps you think in objects: - it describes structure (properties, methods); - it can be implemented by a class (`implements`); - it can be extended (`extends`); - it does not allow union logic (unlike `type`). > That is why an interface is perceived as an "object blueprint", > not just a "type". --- ## 6. `type` is a universal tool, but not object-oriented `type` can describe: - unions (`|`), - intersections (`&`), - tuples (`[string, number]`), - primitives (`string | number`), - functions (`(a: number) => string`). ```javascript type Result = "success" | "error"; type Point = [number, number]; ``` > But such cases are **not object structures**, > and there `type` is irreplaceable, > while for data models and class interfaces it makes more sense to use `interface`. --- ## 7. So in practice: | Situation | What to choose | Why | |---|---|---| | Describing an object or entity | `interface` | Flexible, extensible, readable | | Describing a class contract | `interface` | Supports `implements` | | Typing API responses, DTOs, models | `interface` | Can be extended and merged | | Union / intersection, tuples, functions | `type` | Flexibility and versatility | | Primitives | `(string \| number)` | `type` | --- ## Summary > Interfaces are more often used for **objects** because: > > 1. They are **specifically created** to describe the structure of objects and classes. > 2. They can be **extended** (`extends`) and **merged** (merging). > 3. They naturally integrate with **OOP** (`implements`). > 4. They are **self-documenting** and read well as "data contracts". > 5. They are **part of TypeScript's philosophy**, which is built around object structures.For the reviewerNote to the moderator (optional)Visible only to the moderator. Helps review go faster.