You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
fix(utils): keep falsy non-nullish values in asArray - #1114
asArray is typed to return NonNullable<T> items, so only null and undefined should become []. The check was value ? [value] : [], which also dropped 0, "" and false: asArray(0) returned [].
Changed it to value != null. Tests for wrapping, arrays, falsy values and nullish values are in packages/utils/test/index.test.ts; the falsy one fails on main and passes now. The tests of the packages that use asArray pass too, and eslint and prettier are clean. Changeset included.
Summary by CodeRabbit
Bug Fixes
Fixed asArray so values such as 0, false, and empty strings are wrapped in arrays instead of being discarded. Arrays remain unchanged, while null and undefined still return an empty array.
No actionable comments were generated in the recent review.
Walkthrough
asArray now wraps falsy non-nullish values in an array. Tests cover scalar values, existing arrays, null, and undefined. A patch Changeset documents the fix.
Changes: asArray behavior
Layer / File(s)
Summary
Update and validate asArray behavior packages/utils/src/index.ts, packages/utils/test/index.test.ts, .changeset/utils-as-array-falsy.md
asArray now wraps non-nullish scalars, including 0, "", and false. Tests check these values, array identity, and empty-array results for null and undefined. A patch Changeset documents the change.
asArray now keeps 0, empty strings and false instead of returning an empty array. This fixes the reported bug. Callers that relied on falsy values being dropped would see different results, but no such caller has been identified. The change is small, tested, and easy to revert.
Pre-merge checks: 4
Check name
Status
Explanation
Description Check
Check skipped - CodeRabbit’s high-level summary is enabled.
Title check
The title names the main change: asArray now keeps falsy non-nullish values (0, "", false) by checking value != null instead of truthiness. The raw summary and PR objectives both describe this same ch…
Linked Issues check
Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check
Check skipped because no linked issues were found for this pull request.
Full details: Title check
Explanation
The title names the main change: asArray now keeps falsy non-nullish values (0, "", false) by checking value != null instead of truthiness. The raw summary and PR objectives both describe this same change to packages/utils/src/index.ts, its tests, and the changeset. The title is specific and accurate, and it follows the conventional commit style.
Finishing Touches
Generate unit tests (beta)
Create a new PR
Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.
File: No configuration file from this repository applied
Commit: Unavailable
Layers: defaults
Review profile: CHILL
Plan: Advanced
Run ID: 8d1bae3f-a32f-4fd5-8b3a-c84faae0fe7b
Commits
Reviewing files that changed from the base of the PR and between e936941 and ce7d81a.
Files selected for processing: 3
.changeset/utils-as-array-falsy.md
packages/utils/src/index.ts
packages/utils/test/index.test.ts
Included review availability: This review used your included allowance. Your plan provides up to 4 included reviews per hour; 3 remain after this review.
This branch has not been deployed
No deployments
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
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.
asArrayis typed to returnNonNullable<T>items, so onlynullandundefinedshould become[]. The check wasvalue ? [value] : [], which also dropped0,""andfalse:asArray(0)returned[].Changed it to
value != null. Tests for wrapping, arrays, falsy values and nullish values are in packages/utils/test/index.test.ts; the falsy one fails on main and passes now. The tests of the packages that useasArraypass too, and eslint and prettier are clean. Changeset included.Summary by CodeRabbit
asArrayso values such as0,false, and empty strings are wrapped in arrays instead of being discarded. Arrays remain unchanged, whilenullandundefinedstill return an empty array.