Skip to content

fix(defaults): handle undefined and null sources in compat/defaults#1233

Merged
raon0211 merged 5 commits intotoss:mainfrom
hwibaski:feature/defaults
Oct 24, 2025
Merged

fix(defaults): handle undefined and null sources in compat/defaults#1233
raon0211 merged 5 commits intotoss:mainfrom
hwibaski:feature/defaults

Conversation

@hwibaski
Copy link
Copy Markdown
Contributor

Summary

Before, the sources parameter had a strict type, so unless a user intentionally hacked around the type system, null or undefined values were never passed.
Later, while making the type compatible with Lodash, it became possible to pass nil (null or undefined) values.
When this happened, compat/defaults would throw an error, while Lodash’s defaults would simply ignore those values without a problem.

This change fixes that issue by making compat/defaults handle nil values the same way as Lodash — safely skipping them without errors.

Before Change

The following code would throw an error when a null or undefined source parameter is provided:

import { defaults as esDefaults } from "es-toolkit/compat";

function main() {
  esDefaults({ a: 1 }, null);
}

main();
image

Note: In Lodash’s defaults, passing null or undefined as a source does not cause an error — it simply ignores those values.
The current behavior in es-toolkit is inconsistent with that.

After Change

The defaults function has been updated to safely ignore null or undefined sources.
If a nil (null/undefined) source is passed, it will simply be skipped without throwing an error.

import { defaults as esDefaults } from "es-toolkit/compat";

function main() {
  esDefaults({ a: 1 }, null); // returns { a: 1 }
}

main();

Testing

image

Coverage

image

…tion

* `defaults` 함수에서 `undefined` 및 `null` 소스를 처리하도록 수정
* 관련 테스트 케이스 추가
@vercel
Copy link
Copy Markdown

vercel Bot commented Jun 25, 2025

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

Project Deployment Preview Comments Updated (UTC)
es-toolkit Ready Ready Preview Comment Oct 24, 2025 4:03am

@codecov-commenter
Copy link
Copy Markdown

codecov-commenter commented Jun 25, 2025

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 99.88%. Comparing base (ae40de3) to head (a275887).
⚠️ Report is 6 commits behind head on main.

Additional details and impacted files

Impacted file tree graph

@@           Coverage Diff           @@
##             main    #1233   +/-   ##
=======================================
  Coverage   99.88%   99.88%           
=======================================
  Files         468      468           
  Lines        4451     4453    +2     
  Branches     1310     1311    +1     
=======================================
+ Hits         4446     4448    +2     
  Misses          5        5           
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@hwibaski hwibaski changed the title fix(compat/defaults): handle undefined and null sources in compat/defaults fix(defaults): handle undefined and null sources in compat/defaults Jun 25, 2025
@hwibaski
Copy link
Copy Markdown
Contributor Author

hwibaski commented Jul 7, 2025

@dayongkr
Hi, I noticed this PR hasn't been reviewed for a couple of weeks.
If you have a moment, could you review it?
I just mentioned you directly in case you might have missed it.
If it was a bother, I won’t mention you directly next time — sorry about that!

NotIvny added a commit to NotIvny/Yunzai that referenced this pull request Sep 3, 2025
似乎没修
toss/es-toolkit#1223
toss/es-toolkit#1233
我做了点改动:
const source = sources[i] != null ? sources[i] : [];
TimeRainStarSky pushed a commit to TimeRainStarSky/Yunzai that referenced this pull request Sep 3, 2025
似乎没修
toss/es-toolkit#1223
toss/es-toolkit#1233
我做了点改动:
const source = sources[i] != null ? sources[i] : [];
TimeRainStarSky pushed a commit to TimeRainStarSky/Yunzai that referenced this pull request Sep 3, 2025
似乎没修
toss/es-toolkit#1223
toss/es-toolkit#1233
我做了点改动:
const source = sources[i] != null ? sources[i] : [];
raon0211
raon0211 previously approved these changes Oct 24, 2025
Copy link
Copy Markdown
Collaborator

@raon0211 raon0211 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry for the late review. Really appreciate your work!

@raon0211 raon0211 merged commit ef622d3 into toss:main Oct 24, 2025
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.

4 participants