October DealsAmazon USOctober deal check: compare before you payAmazon US: current deals, useful picks and tech finds.Check DealsPC HealthRecommendedCrashes, freezes, slowdowns? Check your PC nowSpot repairable issues before they interrupt work.Check PCOctober DealsAmazon USDeal season is back - check today's better picksAmazon US: current deals, useful picks and tech finds.See Picks×
Skip to content
World desk3 min

How to Model Overrideable Properties with TypeScript Utility Types

Use Omit & Overrides to replace selected property types without retaining conflicting requirements from the base type.
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 a type, remove the overlapping keys with Omit and then intersect the remaining shape with the replacement properties:

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

This is a compile-time type transformation, not a runtime merge or fallback. Your JavaScript still needs to construct or update values accordingly.

As an Amazon Associate I earn from qualifying purchases.

Why an intersection alone does not override a property

An intersection such as Base & Overrides combines the requirements from both types. When both contain the same key with incompatible types, the property must satisfy both declarations; TypeScript does not treat the second type as a replacement. The handbook describes this behavior for intersection types.

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

For example, number & string is not a property that accepts either a number or a string. If the intended result is to change port from a number to a string, remove the old port before combining in the new one.

Replace selected properties with Omit and an intersection

Omit<Base, keyof Overrides> retains base properties except those whose keys appear in Overrides. Intersecting that result with Overrides gives the override shape ownership of duplicate keys. TypeScript documents Omit among its utility types.

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>;
// Equivalent property shape:
// {
//   host: string;
//   port: string;
//   tls?: "required" | "optional";
// }

host remains from the base, while port and tls come from the override shape. Because tls is optional in Overrides, it is optional in the resulting type.

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

Make every override field optional

When the override type describes fields that may be supplied, rather than fields that must be present, use Partial:

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
type PartialOverride<Base, Overrides> =
  Omit<Base, keyof Overrides> & Partial<Overrides>;

This makes every property from Overrides optional. It does not restore the original base property type when an override is absent: those keys were removed from the base side first. If a value should fall back to the old setting, implement that behavior in the code that builds the value, or design a type that deliberately represents the possible states. Partial changes property optionality; it does not perform runtime fallback.

Choose the pattern that matches the intent

Approach Duplicate keys Required or optional Use it when
Omit<Base, keyof Overrides> & Overrides Removed from the base side, then supplied by the override side As declared in Overrides You intentionally replace selected property types.
Omit<Base, keyof Overrides> & Partial<Overrides> Removed from the base side, then supplied by the partial override side All override properties become optional Override fields may be omitted and no type-level fallback is intended.
interface New extends Base Duplicate declarations must be compatible; incompatible properties produce an error As declared, subject to compatibility You are extending a shape compatibly, not replacing a property type.
Base & Other Both sets of requirements remain As declared by both types The shapes contribute distinct members or compatible duplicates.

Use interface extension when a compatible extension is the goal: TypeScript checks duplicate property declarations for compatibility. Use the Omit-and-intersection pattern when changing a property’s type intentionally. See the handbook’s interface documentation.

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

Version and edge-case checks

Omit is documented as available beginning with TypeScript 3.5; the TypeScript 3.5 release notes cover its introduction. If a project uses an older compiler, verify utility-type availability before adopting this alias. The utility-types reference records Partial as available since TypeScript 2.1.

TypeScript’s intersection checking has changed across releases. The TypeScript 3.9 release notes, for example, discuss stricter checks involving optional properties and intersections, as well as reducing intersections with incompatible discriminant properties. Union inputs, optional keys, readonly modifiers, index signatures, and generic aliases can have additional interactions; check the exact type with the compiler version and configuration used by your project.

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.

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.

Leave a Reply

Your email address will not be published. Required fields are marked *

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

More from the Wire

  1. World desk4 min
    How to Spot an AI Voice Scam Before Sending MoneyDon’t rely on how a caller sounds. Pause, call back through a known number, and verify the emergency with another trusted person before sending money.
  2. Mountain View desk4 min
    Google’s SynthID Detector: How to Check AI-Generated Images, Video and AudioGoogle’s SynthID Detector looks for an embedded watermark in supported images, video and audio. Here is what its results do—and do not—show.
  3. Redmond desk20 min
    How to create a link to File or Folder in Windows 11Windows 11 gives you several ways to point to a file or folder without moving or duplicating it. You can create a desktop shortcut,…
Recommended PC Tool
Recommended PC Tool
Windows Errors? Fix Them Before They SpreadFree repair scan
Crashes, No Sound, or Screen Glitches?Free driver scan

Two free Windows tools

One Free Minute Could Fix That PC

Before you go - each of these free tools takes about a minute and tackles what quietly slows a Windows PC down.

Special offer. View Outbyte info, uninstall instructions, EULA, and Privacy Policy.