Repository navigation
Conversation
Sorting by a criterion that returns a symbol threw 'TypeError: Cannot convert a Symbol value to a number', because compareValues compared regular values with '<'. Rank symbols after regular values (before NaN, null and undefined, keeping the existing order), so they sort stably like lodash and es-toolkit/compat do. Signed-off-by: Ultroncn <82553854+Ultroncn@users.noreply.github.com>
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
This branch was successfully deployed
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.
sortBy/orderBythrowTypeError: Cannot convert a Symbol value to a numberwhen a sort key is a Symbol, because the sharedcompareValuescompares regular values with<directly. lodash and the compat build sort Symbol values fine, so the main package crashing here is a bug.This ranks Symbols alongside the other special values in
nullishRank(after regular values, beforeNaN/null/undefined, matching the main package's existingNaN < null < undefinedorder), so Symbols never reach the<comparison. Two Symbols compare equal (rank tie returns 0), keeping the sort stable.Verified locally: the 3 new tests fail on the old implementation with the TypeError and pass with the fix;
src/array/sortBy.spec.ts+src/array/orderBy.spec.ts20/20 pass, compatsortBy/orderByspecs 43/43 pass.Note: this follows the main package's own ordering convention rather than lodash's (lodash puts
NaNlast); only the compat build promises lodash parity, and the main package's existing tests pinNaN < null < undefined.