Confusing/inconsistent merging
Closed this issue · 2 comments
Looking at this code:
updeep({ a: { b: 'value' } }, { a: 'test' })
I was expecting the output to be:
{ a: { b: 'value' } }
However, the output was actually:
{ a: { '0': 't', '1': 'e', '2': 's', '3': 't', b: 'value' } }
This seems like a bug, but just in case this was intentional, I next tried this:
updeep({ a: { b: 'value' } }, { a: ['test'] })
Which, I would have previously expected to output:
{ a: { b: 'value' } }
but after seeing the above example thought I might see something more like:
{ a: ["test", b: "value"] }
// where the value at key `a` is an array with string "test" at index 0 and a second key `b` with value "value"
// I know the above isn't valid syntax, but it is how chrome logs that particular scenario
It was neither, however, and instead gave:
{ a: [ 'test' ] }
As is explained in the docs, the updates are the first parameter, not the second. The second is the object being updated. Thus, the behavior you see is correct. The weird string-to-numeric keys problem is probably because you're merging a string with an object.
@tylermercer is correct, it looks like things are working as intended, but because the argument order is atypical in JavaScript, it is somewhat surprising. It's designed this way to support currying, but it does require learning/memorization that this is the case.