Explore Library
Code Quiz

Merging Objects with a Single Type Parameter

A single generic parameter forces both arguments into a union, collapsing the inferred type.

Codetypescript
function merge<T>(a: T, b: T): T {
  return { ...a, ...b };
}

const config = merge({ debug: true }, { level: 3 });

config.debug; // want this
config.level; // and this

The runtime object has both `debug` and `level`, yet the compiler rejects `config.level` (and `config.debug`). What is the bug and how do you fix it?