Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Use extends to inherit an interface’s members and add new ones. If the child interface redeclares a property, its type must remain compatible with the inherited type: it may narrow the values callers can provide, but it cannot break the base contract by widening the type or making a required property optional.

Extend an interface with extends

Declare a new interface and name the existing interface after extends. The child contract includes the base members, so you can add fields without repeating them.

interface Base {
  id: string | number;
}

interface WithStringId extends Base {
  id: string;
  label: string;
}

WithStringId keeps the base guarantee that id has an allowed value, while narrowing the child’s accepted values to string. A string is assignable to string | number, so this redeclaration is compatible. TypeScript’s rules here follow structural and assignment compatibility: Interfaces — Extending Interfaces and Type Compatibility.

What makes a redeclared property compatible?

Think in terms of the contract inherited by consumers. A value described by the child must still honor what the base type promises. A child may restrict which values it allows; it must not admit values that violate the base property’s type, nor remove a guarantee made by the base.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Narrowing can be compatible

Given a base property typed as string | number, a child property typed as string is compatible because every string is also a member of the base union. The child contract is more specific.

Widening is not an override

If the base property is string, redeclaring it as string | number would allow numbers that the base contract does not permit. That is incompatible, so an interface cannot silently replace the inherited type with the wider one.

Rank #2
TypeScript Programming Language - Software Engineer & Coder T-Shirt
  • TypeScript implements a superset of syntax for strictly typed development, facilitating deep static analysis and enhanced development environment integration. The compiler translates source into standard script formats, ensuring parity across any runtime.
  • TypeScript is ideal for front-end developers, full-stack engineers, and software architects who build large-scale web applications. It serves those looking to improve code excellence, reduce bugs through static checking, and maintain complex projects more.
  • Lightweight, Classic fit, Double-needle sleeve and bottom hem

Optionality is part of the contract

A required base property cannot become optional in the child. The base promises that the property exists; marking it optional would allow child-shaped values that break that promise.

interface Base {
  id: string;
}

interface WithOptionalId extends Base {
  id?: string; // Error: the required base property is no longer guaranteed
}

These examples illustrate the handbook’s structural compatibility rules; they do not specify a particular TypeScript compiler version. For the general rule, see Object Types and Type Compatibility.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Choose the right construct for alternatives and conflicts

When the goal is to allow several value types, make that choice explicit in the property’s type or model the alternatives as separate variants. Neither interface extension nor an intersection acts as a general-purpose property override.

Use a union for one property with multiple allowed values

If the base contract should accept either a string or a number, declare that union on the base property, as in id: string | number. A derived interface can then narrow it if appropriate, as the earlier example does.

Use a discriminated union for distinct shapes

If alternatives have different fields or guarantees, represent them as separate object types distinguished by a shared literal property. Each variant can then state its own valid shape without pretending that one interface is a subtype of the other.

Do not use an intersection to select one property type

An intersection requires a value to satisfy both constituent types. For example, combining a property typed string with one typed number does not mean “string or number”; it requires both, which cannot describe an ordinary value. Interface extension reports incompatible inherited declarations rather than treating them as an override. See Object Types.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Extending multiple interfaces

An interface may extend more than one base:

interface Identified {
  id: string;
}

interface Labeled {
  label: string;
}

interface Item extends Identified, Labeled {
  active: boolean;
}

This combines the inherited members when their declarations can be reconciled. If two bases declare the same property incompatibly, the combined contract cannot satisfy both declarations and TypeScript reports a conflict. The same compatibility principle applies when a child redeclares an inherited property. See Interfaces — Extending Interfaces and Object Types.

Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

Distinguish extension from merging and augmentation

These mechanisms all affect interface types, but they solve different problems.

  • Extension: A newly named interface inherits a base with extends. Use it for a related, more specific contract.
  • Declaration merging: Separate declarations with the same interface name are combined. Repeated non-function members must have the same type; same-name function members form overloads. This is distinct from creating a child interface. See Declaration Merging.
  • Module augmentation: A declaration can augment an existing named export, often to describe a runtime extension implemented elsewhere. It does not add runtime code; the implementation must exist independently. The handbook also documents limits: augmentation cannot introduce new top-level declarations and cannot augment a default export. See Classes.

Special cases: index signatures and class types

Inherited index signatures constrain named properties

If a base interface has a string index signature whose values are numbers, its named properties must also be compatible with that value type. Adding a named property typed string would conflict. If the contract genuinely allows both kinds of values, widen the index signature to an appropriate union. See Interfaces.

An interface can extend a class type

An interface extending a class inherits its member types, not its method implementations. Private and protected members still matter: an interface that inherits them can be implemented only by that class or a subclass in the relevant hierarchy. See Classes.

What’s actually slowing this PC down?

Pick the symptom - the matching free tool is one click away.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Choose the construct that matches your goal

Need Use Reason
Add fields to a reusable base contract interface Child extends Base Keeps the relationship explicit without repeating inherited members.
Combine compatible contracts interface Combined extends A, B Interfaces support multiple bases when their members can be reconciled.
Allow several types for one property A union in the property type A union represents alternatives; an intersection requires both constituent types.
Add a property to a library declaration Module augmentation, when the named export and module resolution permit it It augments an existing declaration, subject to documented limits, but does not add runtime behavior.
Describe unrelated object alternatives A discriminated union Each variant can make its own guarantees without implying subtype inheritance.

Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.