Merges two objects deeply.

Type signature

(
  a: {
    [index: string]: any;
  },
  b: object
) => object

Examples

merge({ a: 1, b: 3 }, {});
// ⇒ { a: 1, b: 3 }
Try in REPL
merge({ a: 1, b: 3 }, { b: 7 });
// ⇒ { a: 1, b: 7 }
Try in REPL
merge(
  { a: 1, b: 3 },
  { b: { d: 8 } }
);
// ⇒ { a: 1, b: { d: 8 } }
Try in REPL
merge(
  { a: 1, b: { c: 3 } },
  { b: { d: 8 } }
);
// ⇒ { a: 1, b: { c: 3, d: 8 } }
Try in REPL

Questions

  • How to merge two objects together?
  • How to deeply merge two objects?

TypeScript sourceJavaScript source