fix(hub-common): modified getProp() logic#2116
Conversation
fix #14633
🦋 Changeset detectedLatest commit: d17b6d4 The changes in this PR will be included in the next version bump. This PR includes changesets to release 1 package
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
There was a problem hiding this comment.
Pull Request Overview
This PR fixes the getProp() function to properly handle falsy values in arrays and undefined paths. Previously, the function would throw errors when accessing properties on undefined objects and would incorrectly return undefined for falsy array elements like null, 0, false, or empty strings.
Key Changes:
- Added an early return guard to prevent errors when accessing properties on
undefinedobjects - Changed array element existence check from truthiness check to proper
inoperator to distinguish between missing elements and falsy values
Reviewed Changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
| packages/common/src/objects/get-prop.ts | Modified the core logic to handle undefined paths safely and properly return falsy array values |
| packages/common/test/objects/get-prop.spec.ts | Added comprehensive test coverage for falsy array elements and undefined path scenarios |
sonofflynn89
left a comment
There was a problem hiding this comment.
Should be good as long as all tests are passing! Just one test comment
…x on missing nested properties
heyisundefined, then accessinghey.hello[0]should returnundefinedinstead of throwing an error.hey.helloexists and the array element at index0contains a falsy value (e.g.,null,0,'',false), then return that actual value.undefinedwhen the path truly doesn’t exist. Otherwise, return the actual value, even if it’s falsy.Instructions for testing:
Updated meaningful TSDoc to methods including Parameters and Returns, see Documentation Guide
Either ran
npm run changesetor this change does not require a release.These changes have been verified by QA using a
?uiVersionthat includes a PR-Preview of this branch and thev_reqlabel has been applied to the issue.OD-UI E2E tests pass against these changes using a
?uiVersionthat includes a PR-Preview of this branch