Simplify Flattens Intersection Types

A one-line mapped type flattens Defaults & Overrides intersections so hover tooltips and ExpectEqual comparisons show a single clean object shape.

TypescriptConfig Management

Code

typescriptsnippet
26 lines
// A homomorphic mapped type copies every key once, collapsing an
// intersection of object types into one flat shape for hover and compare.
type Simplify<T> = { [K in keyof T]: T[K] } & {};

interface BaseConfig {
  retries: number;
  timeoutMs: number;
}

type Overrides = { timeoutMs?: number; label?: string };

// Raw intersections keep both members listed; Simplify merges them
type ResolvedRaw = BaseConfig & Required<Overrides>;
type Resolved = Simplify<ResolvedRaw>;

type ExpectEqual<T, U> =
  (<V>() => V extends T ? 1 : 2) extends <V>() => V extends U ? 1 : 2 ? true : never;

type Checks = [
  ExpectEqual<Resolved, { retries: number; timeoutMs: number; label: string }>,
];
type _Checks = Checks;

const resolved: Resolved = { retries: 3, timeoutMs: 1_500, label: 'billing' };
console.log(resolved.retries, resolved.timeoutMs, resolved.label);
console.log('keys:', Object.keys(resolved).sort().join(','));

Output

Captured from a sandboxed run of this snippet in the build pipeline.

3 1500 billing
keys: label,retries,timeoutMs

Runtime behavior

The top-level object literal pins retries, label as plain values — no derivation, no imports behind them.

Watch out for

  • No dependencies section needed; the standard library is the whole story.

Applying it

Output lines are prefixed (keys:), so each printed result carries the name of its step.

Statements that matter

(<V>() => V extends T ? 1 : 2) extends <V>() => V extends U ? 1 : 2 ? true : never;
type Simplify<T> = { [K in keyof T]: T[K] } & {};

Interactive Tools for This Topic

FAQ

Is anything beyond the standard library required?
Nothing beyond the standard library — the snippet is dependency-free.