Unexpected behaviour when merging (YUP generated) objects with lodash's "merge"

Viewed 54

I have 2 YUP schemas. Getting the default object of each one and then merging them with lodash's "merge" doesn't return what I'd expect.

The entire operation looks like this:

a = getSchema1(); // { parameters: {} }
b = getSchema2(); // { parameters: { foo: [] } }
result = merge({}, b, a);

// result is { parameters: {} }
// but it should be { parameters: { foo: [] } } 

The weird part is that if I call JSON.parse(JSON.stringify(a)), the merge operation returns what I'm expecting.

result = merge({}, b, JSON.parse(JSON.stringify(a)));
// result is { parameters: { foo: [] } } 

Why is this happening?

Full repro case: https://codesandbox.io/s/elated-thompson-m4mbn?file=/src/index.js

0 Answers
Related