suggestion: validate inputs being of type object, early bail-out if necessary #38
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Hi!
Thank you for maintaining this project.
We've been using it in production for the past 6months as our go-to shallow-equality-check utility.
However, we've recently been bit by a bug caused by our failure to ensure the input parameters we're passing to
shallowEquals
are indeed objects or arrays.To illustrate, we've had a specific case where the input values were different numbers, unfortunately marked as
any
:I know this library is meant to be used with input values which the consumer knows are objects, and the library does not aim to provide a shallow-equality-check utility accounting for all the possible types & matching edge-cases.
However, I do believe it would be a valuable addition to introduce a bare minimum
typeof
-based validation at the right place, to avoid consumers treating some non-object
-typeof values as being "shallow-equal", which is what this PR does.I believe this direction still matches the project's philosophy since there are a couple of existing, similar-to-some-degree checks in the current implementation, such as loosely checking for falsy values in
shallowEqualArrays
notably.Thank you for your consideration.