Shallow Merges objects or arrays.

Syntax

TypeScript
import { shallowMerge } from '@opentf/std';
shallowMerge(obj1, ...objN);
Info

Immutable: This does not mutate the given arrays or objects.

Warning

Sources are copied without Object.assign, so an own __proto__ key — what JSON.parse produces for {"__proto__":{...}} — cannot replace the result's prototype. This matters when merging defaults with an untrusted request body.

Examples

TypeScript
const a = { a: 1 };
const b = { b: 2 };
shallowMerge(a, b); //=> { a: 1, b: 2 }

const a = [1];
const b = [2];
const c = [3];
shallowMerge(a, b, c); //=> [3]
Last updated on
Edit this page