fix[isNumber]: remove instanceof Number check#1726
Open
JetProc wants to merge 2 commits into
Open
Conversation
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
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
…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.
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
isNumberwas the only core predicate that included aninstanceofcheck alongsidetypeof. The other primitive type guards —isString,isBoolean, andisSymbol— all rely solely ontypeof, makingisNumberinconsistent with the rest of the predicate API.This PR removes the
instanceof Numbercheck fromsrc/predicate/isNumber.tsso thatisNumberonly returnstruefor primitive numbers, consistent with the other predicates.Changes
src/predicate/isNumber.ts: removed|| x instanceof Number, updated JSDocsrc/predicate/isNumber.spec.ts: movednew Number(42)from thetruecase to thefalsecasedocs/reference/predicate/isNumber.md(en, ko, ja, zh_hans): updated to reflect the new behaviorNotes
The
compatversion (src/compat/predicate/isNumber.ts) is intentionally left unchanged, as it must match Lodash's behavior.Closes #1652