Skip to content

fix[isNumber]: remove instanceof Number check#1726

Open
JetProc wants to merge 2 commits into
toss:mainfrom
JetProc:fix/isNumber-remove-instanceof-check
Open

fix[isNumber]: remove instanceof Number check#1726
JetProc wants to merge 2 commits into
toss:mainfrom
JetProc:fix/isNumber-remove-instanceof-check

Conversation

@JetProc
Copy link
Copy Markdown

@JetProc JetProc commented May 18, 2026

Summary

isNumber was the only core predicate that included an instanceof check alongside typeof. The other primitive type guards — isString, isBoolean, and isSymbol — all rely solely on typeof, making isNumber inconsistent with the rest of the predicate API.

This PR removes the instanceof Number check from src/predicate/isNumber.ts so that isNumber only returns true for primitive numbers, consistent with the other predicates.

Changes

  • src/predicate/isNumber.ts: removed || x instanceof Number, updated JSDoc
  • src/predicate/isNumber.spec.ts: moved new Number(42) from the true case to the false case
  • docs/reference/predicate/isNumber.md (en, ko, ja, zh_hans): updated to reflect the new behavior

Notes

The compat version (src/compat/predicate/isNumber.ts) is intentionally left unchanged, as it must match Lodash's behavior.

Closes #1652

isNumber was the only core predicate that included an instanceof check
alongside typeof. isString, isBoolean, and isSymbol all rely solely on
typeof checks, making isNumber inconsistent with the rest of the API.

This commit removes the instanceof Number check so that isNumber only
returns true for primitive numbers, consistent with the other predicates.

The compat version remains unchanged as it needs to match Lodash behavior.

Closes toss#1652
@JetProc JetProc requested review from dayongkr and raon0211 as code owners May 18, 2026 07:40
@vercel
Copy link
Copy Markdown

vercel Bot commented May 18, 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 18, 2026 7:48am

Request Review

…heck

Update all four language docs (en, ko, ja, zh_hans) to clarify that
isNumber only returns true for primitive numbers, and that wrapped
Number objects (e.g. new Number(42)) return false.
@JetProc JetProc changed the title fix(predicate): remove instanceof Number check from isNumber fix[isNumber]: remove instanceof Number check May 18, 2026
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.

Why does isNumber include instance check?

1 participant