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

To replace selected property types while keeping the rest of an object shape, remove the overlapping keys from the base type, then intersect it with the override type:

type Override<Base, Overrides> = Omit<Base, keyof Overrides> & Overrides;

This is a compile-time type pattern, not a runtime merge or fallback. The code that creates or updates an object still determines its actual values.

Why a plain intersection does not override a property

An intersection such as Base & Overrides combines the requirements from both types. If both define port with incompatible types, the resulting property must satisfy both requirements; TypeScript does not treat the second type as taking precedence. The handbook notes that properties with different types in an intersection are merged automatically: TypeScript: Object Types.

For example, intersecting { port: number } with { port: string } does not produce a string-valued port. Use Omit to remove the original declaration before combining the shapes.

Free tools Windows power users keep installed

One-click scans. No signup required.

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

Replace selected properties with Omit and an intersection

Omit<Base, keyof Overrides> keeps the base properties except those named in Overrides. The intersection then adds the override properties, so the override side defines the shared keys.

type Override<Base, Overrides> = Omit<Base, keyof Overrides> & Overrides;

type ServerConfig = {
  host: string;
  port: number;
  tls: boolean;
};

type Overrides = {
  port: string;
  tls?: "required" | "optional";
};

type EffectiveConfig = Override<ServerConfig, Overrides>;

EffectiveConfig retains host: string, replaces port: number with port: string, and uses the override declaration tls?: "required" | "optional". The official utility-types reference describes Omit as picking properties and removing specified keys: TypeScript: Utility Types.

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

Choose the pattern that matches your intent

Intent Pattern Effect
Replace selected property types Omit<Base, keyof Overrides> & Overrides Removes matching base keys, then uses the declarations in Overrides.
Make all override properties optional Omit<Base, keyof Overrides> & Partial<Overrides> Removes matching base keys and marks the override properties optional.
Extend a shape compatibly interface Extended extends Base { ... } Checks that duplicate property declarations are compatible; incompatible duplicates produce an error.
Combine distinct or compatible shapes A & B Requires the combined value to meet the members of both types; it does not replace conflicting declarations.

Partial<T> makes the properties of T optional. It does not retain the original base type for a key removed by Omit, and it does not fill in a value at runtime. For example, an omitted optional port in the partial-override shape is not thereby guaranteed to use ServerConfig‘s numeric port. If the application needs that fallback, implement it in the value-construction or update logic.

When interface extension is a better fit

Use interface extension when you are adding members and any repeated property declarations are meant to remain compatible. TypeScript reports an error for incompatible duplicate properties in an extending interface. When the purpose is deliberately to replace a property’s type, a type alias using Omit and an intersection expresses that intent instead. See TypeScript: Interfaces and the Object Types handbook.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

Check TypeScript version and edge cases

The official release notes document Omit as available starting with TypeScript 3.5: TypeScript 3.5 release notes. The utility-types reference documents Partial as available since TypeScript 2.1. Projects on earlier compiler versions should verify utility availability before adopting these aliases.

Intersection checking has also changed across compiler versions. TypeScript 3.9 documented stricter checks involving optional properties and intersections, along with reductions of intersections containing incompatible discriminant properties: TypeScript 3.9 release notes. Union inputs, optional and readonly keys, index signatures, and generic aliases can introduce additional behavior. Validate the exact type in the project’s installed TypeScript version and compiler configuration rather than assuming one example covers every case.

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.