lukeed / dset

A tiny (194B) utility for safely writing deep Object values~!
MIT License
754 stars 22 forks source link

docs(dset): Add `merge` function typing and add JSDoc documentation for `dset` and `dset/merge` #45

Open aidarkhanov opened 3 months ago

aidarkhanov commented 3 months ago

Includes type definitions to handle deep merging of nested objects and overwriting arrays.

The types ensure that primitive values from the second argument (U) overwrite those in the first (T), while arrays are replaced entirely, not merged element-wise.

Example:

const obj1 = { a: { b: [1, 2] }, c: null, d: "jaja" };
const obj2 = { a: { b: [3, 4], c: [5, 6] } };

const result = merge(obj1, obj2);
// const result: {
//   a: {
//     c: number[];
//     b: number[];
//   };
//   c: null;
//   d: string;
// }

Also, adds JSDoc to the function type declarations for documentation.