-
Notifications
You must be signed in to change notification settings - Fork 216
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Why would deepmerge assign 'undefined' attributes? #53
Comments
deepmerge operates on all properties of the input objects, no matter what their value is. It may be that most people would assume the opposite - though I see that lodash's Making a breaking change for something fairly opinionated like this seems untenable. I worry about feature creep, but I could see the argument for this. I wouldn't be against a pull request adding a new We could also talk about a general solution - allowing users to pass in a Anyone have thoughts? |
I think if you can gather anything from the lodash example it's that both functionalities can be valuable. undefined is a possibly desirable value just like any other. I support addition of a custom function the user can define to dictate merge functionality, that said assuming the need for undefined is a common case I would also like to see a function that supports it out of the box. |
Is there a workaround or and options not to merge |
Yeah, you can pass in a Something like const customMerge = key => (a, b) => b === undefined ? a : deepmerge(a, b) |
@TehShrike unfortunately your suggestion is not working 🤔 |
This should work : const customMerge = () => (a, b) => {
const c = Object.keys(b)
.filter([key, value] => value !== undefined)
.reduce((obj, [key, value]) => ({
...obj,
key : value,
}, {});
return deepmerge(a, c);
}; |
|
@TehShrike Could this issue be reopened? We're having the same issue and the suggested solutions do not work |
Currently
deepmerge
overwrites non-void attribute withundefined
attribute:Why is this a desired behaviour?
IMHO, the conventional
merge
method should skipundefined
value. The popular libararyLodash
also aggrees that rule, see http://stackoverflow.com/a/33247597/1401634.Would you please at least provide an option to turn this behaviour off?
Cheers
The text was updated successfully, but these errors were encountered: