Skip to content

fix(compat/omitBy): do not treat plain objects with numeric length as array-like#1709

Merged
raon0211 merged 2 commits into
mainfrom
work/omitBy
May 8, 2026
Merged

fix(compat/omitBy): do not treat plain objects with numeric length as array-like#1709
raon0211 merged 2 commits into
mainfrom
work/omitBy

Conversation

@raon0211
Copy link
Copy Markdown
Collaborator

@raon0211 raon0211 commented May 8, 2026

Summary

Closes #1706

omitBy from es-toolkit/compat returned {} for any plain object that happened to have a numeric length property (e.g. Error instances, pg driver errors, winston info objects), because it treated array-likeness as authoritative. Lodash's _.omitBy does not — it operates on own enumerable keys regardless of length. 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

  • Drop the isArrayLike branch in src/compat/object/omitBy.ts and unconditionally walk [...keysIn(object), ...getSymbolsIn(object)]. keysIn already handles real arrays correctly (returns indices as string keys), so the branch was unnecessary and actively wrong for plain objects with a numeric length.
  • Remove now-unused range and isArrayLike imports.
  • Add two regression tests in src/compat/object/omitBy.spec.ts:
    • plain object with numeric length is preserved when no value is nil
    • symbol-keyed properties survive on objects that also carry a numeric length

Test results

✓ src/compat/object/omitBy.spec.ts (11 tests) 3ms

Test Files  1 passed (1)
     Tests  11 passed (11)

…as array-like

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
@raon0211 raon0211 requested a review from dayongkr as a code owner May 8, 2026 06:53
@vercel
Copy link
Copy Markdown

vercel Bot commented May 8, 2026

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
es-toolkit Ready Ready Preview, Comment May 8, 2026 7:02am

Request Review

@raon0211 raon0211 merged commit 6e449e4 into main May 8, 2026
8 of 10 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

compat.omitBy diverges from lodash for plain objects with a numeric length property

1 participant