Skip to content

fix(utilities): ensure consistent typing for objectEntries, objectKeys and objectValues#857

Merged
favna merged 6 commits intosapphiredev:mainfrom
GeniusTimo:patch-1
Jan 29, 2025
Merged

fix(utilities): ensure consistent typing for objectEntries, objectKeys and objectValues#857
favna merged 6 commits intosapphiredev:mainfrom
GeniusTimo:patch-1

Conversation

@GeniusTimo
Copy link
Contributor

I noticed that these functions have return types that do not match the type assertions within their implementations. After reviewing the pull requests that introduced these functions, I believe the idea to use ArrayLike<infer Values> (see #474 (comment)) may have unintentionally caused some confusion. The idea for the objectValues function was only implemented to the type assertion within the function and not yet for its return type (de87080 ✔)

To improve consistency, the same idea was adapted for the objectEntries function (see #471 (comment)). However, it was implemented as if Object.entries returned the values, not the entries, when dealing with array-like objects (9d6d3e8 ✔)
Because the return type of the function was not updated to reflect this change, it had no real impact. To align with the intended consistency, I have updated the return type to match the corrected type assertion (34c3205 ✔)

The type of the values within an array-like object is not relevant to the objectKeys function. However, the idea was also applied to that type assertion (see #472 (comment)) Because the return type was not adjusted accordingly, this change also had no actual effect. I have fixed this as well (b43fba0 ✔)

This pull request is meant to reduce potential confusion for future contributors. The details regarding the previous implementation are provided for traceability only and are not intended as criticism of or offense to anyone involved back then.

@GeniusTimo GeniusTimo changed the title feat(utilities): Updated objectEntries, objectKeys and objectValues functions to make them more consistent fix(utilities): Ensure consistent typing for objectEntries, objectKeys and objectValues Jan 18, 2025
kyranet
kyranet previously approved these changes Jan 19, 2025
Copy link
Member

@favna favna left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you add unit tests for this using vitest testing types? To ensure that the same mistake is not made in the future because these types are quite complex.

@GeniusTimo
Copy link
Contributor Author

I'm not familiar with vitest yet, but I've tried my best. Since we can't test the type assertion within the function (at least to my knowledge), I feel like checking the return type for arrays is all we can add?

@GeniusTimo GeniusTimo requested a review from favna January 20, 2025 17:45
@favna favna changed the title fix(utilities): Ensure consistent typing for objectEntries, objectKeys and objectValues fix(utilities): ensure consistent typing for objectEntries, objectKeys and objectValues Jan 29, 2025
@favna favna merged commit 598c24a into sapphiredev:main Jan 29, 2025
9 checks passed
@GeniusTimo GeniusTimo deleted the patch-1 branch February 4, 2025 16:01
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.

3 participants