fix(compat/omitBy): do not treat plain objects with numeric length as array-like#1709
Merged
Conversation
…as array-like Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Summary
Closes #1706
omitByfromes-toolkit/compatreturned{}for any plain object that happened to have a numericlengthproperty (e.g.Errorinstances, pg driver errors, winstoninfoobjects), because it treated array-likeness as authoritative. Lodash's_.omitBydoes not — it operates on own enumerable keys regardless oflength. This PR aligns the behavior with lodash.Fixes the regression reported where
omitBy({ level: 'error', message: 'hi', length: 104 }, isNil)returned{}instead of the original object, which also dropped symbol-keyed properties (e.g. winston's triple-beam routing key).Changes
isArrayLikebranch insrc/compat/object/omitBy.tsand unconditionally walk[...keysIn(object), ...getSymbolsIn(object)].keysInalready handles real arrays correctly (returns indices as string keys), so the branch was unnecessary and actively wrong for plain objects with a numericlength.rangeandisArrayLikeimports.src/compat/object/omitBy.spec.ts:lengthis preserved when no value is nillengthTest results