What is @types/object-assign?
@types/object-assign is a TypeScript type definition package for the object-assign library, which is used to copy the values of all enumerable own properties from one or more source objects to a target object. It is commonly used to merge objects.
What are @types/object-assign's main functionalities?
Merging Objects
This feature allows you to merge properties from one or more source objects into a target object. The properties in the target object are overwritten by properties in the source objects if they have the same key.
const objectAssign = require('object-assign');
const target = { a: 1, b: 2 };
const source = { b: 4, c: 5 };
const result = objectAssign(target, source);
console.log(result); // { a: 1, b: 4, c: 5 }
Deep Merging
While object-assign itself does not support deep merging, it can be used in combination with other libraries to achieve deep merging. This example shows a shallow merge where nested objects are not deeply merged.
const objectAssign = require('object-assign');
const target = { a: 1, b: { x: 1 } };
const source = { b: { y: 2 }, c: 3 };
const result = objectAssign(target, source);
console.log(result); // { a: 1, b: { y: 2 }, c: 3 }
Other packages similar to @types/object-assign
lodash
Lodash is a modern JavaScript utility library delivering modularity, performance, and extras. It provides a `_.assign` method similar to object-assign but also includes a `_.merge` method for deep merging. Lodash is more feature-rich and versatile compared to object-assign.
deepmerge
Deepmerge is a library specifically designed for deep merging of JavaScript objects. Unlike object-assign, which performs shallow merges, deepmerge recursively merges nested objects, making it more suitable for complex merging tasks.
merge
The merge package provides both shallow and deep merging capabilities. It is similar to object-assign for shallow merges but also includes options for deep merging, making it more flexible for different use cases.
Installation
npm install --save @types/object-assign
Summary
This package contains type definitions for object-assign (https://github.com/sindresorhus/object-assign).
Details
Files were exported from https://github.com/DefinitelyTyped/DefinitelyTyped/tree/master/types/object-assign.
declare function objectAssign<T, U>(target: T, source: U): T & U;
declare function objectAssign<T, U, V>(target: T, source1: U, source2: V): T & U & V;
declare function objectAssign<T, U, V, W>(target: T, source1: U, source2: V, source3: W): T & U & V & W;
declare function objectAssign<T, U, V, W, Q>(
target: T,
source1: U,
source2: V,
source3: W,
source4: Q,
): T & U & V & W & Q;
declare function objectAssign<T, U, V, W, Q, R>(
target: T,
source1: U,
source2: V,
source3: W,
source4: Q,
source5: R,
): T & U & V & W & Q & R;
declare function objectAssign(target: any, ...sources: any[]): any;
declare namespace objectAssign {}
export = objectAssign;
Additional Details
- Last updated: Tue, 07 Nov 2023 09:09:39 GMT
- Dependencies: none
Credits
These definitions were written by Christopher Brown.