8000 `mergeDeep`: support `arrayMergeMode` option · Issue #1198 · remeda/remeda · GitHub
[go: up one dir, main page]

8000 Skip to content

mergeDeep: support arrayMergeMode option #1198

@adamhl8

Description

@adamhl8

Just discovered Remeda after looking for an alternative to es-toolkit which has some type issues in some cases due to its loose types.

One thing I miss from es-toolkit is its mergeWith utility. Specifically, I use it to deeply merge two objects while concatenating arrays:

import { mergeWith } from "es-toolkit"

mergeWith(target, source, (objValue: unknown, srcValue: unknown) =>
  Array.isArray(objValue) ? objValue.concat(srcValue) : undefined,
)

The MergeDeep type from type-fest that mergeDeep already returns supports this kind of thing:
MergeDeep<Destination, Source, { arrayMergeMode: "spread" }>.

So my suggestion would be something like mergeDeepConcat instead of an actual mergeWith function, because I'm not sure how you'd be able to handle types correctly in the latter case.

function mergeDeepConcat<Destination extends object, Source extends object>(destination: Destination, source: Source):
MergeDeep<Destination, Source, { arrayMergeMode: "spread" }>

Metadata

Metadata

Assignees

No one assigned

    Labels

    runtimeIssues that refer to the runtime behaviortypingSomething type related

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      0