Function: merge()
Overload 1
merge<
T>(target,source,strict?):T&Record<string,unknown>
Defined in: object.ts:33
Merges the properties of source into target and returns the result as a new object. By default, properties present in source but not in target are added to the result. When strict is true, only properties that already exist in target are updated, and no new properties are added.
Type Parameters
T
T extends object
Parameters
target
T
The base object.
source
Partial<T> & Record<string, unknown>
The object whose properties are merged into target.
strict?
false
When true, only existing properties of target are updated. Defaults to false.
Returns
T & Record<string, unknown>
A new object with the merged properties.
Example
merge({ a: 1, b: 2 }, { b: 99, c: 3 }) // { a: 1, b: 99, c: 3 }
merge({ a: 1, b: 2 }, { b: 99, c: 3 }, true) // { a: 1, b: 99 }Overload 2
merge<
T>(target,source,strict):T
Defined in: object.ts:49
Merges the properties of source into target and returns the result as a new object. Only properties that already exist in target are updated — no new properties are added.
Type Parameters
T
T extends object
Parameters
target
T
The base object.
source
Partial<T>
The object whose properties are merged into target.
strict
true
Must be true to restrict merging to existing properties only.
Returns
T
A new object with only the existing properties of target updated.
Example
merge({ a: 1, b: 2 }, { b: 99, c: 3 }, true) // { a: 1, b: 99 }