Skip to content

refactor: improve type declarations by using generics in utils/group #1375

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Mar 1, 2024

Conversation

rajutkarsh07
Copy link
Contributor

@rajutkarsh07 rajutkarsh07 commented Feb 25, 2024

Resolves #1086

Description

What is the purpose of this pull request?

This pull request:

  • Adds generics for improved type safety for the group function.

Related Issues

Does this pull request have any related issues?

This pull request:

Questions

Any questions for reviewers of this pull request?

No.

Other

Any other information relevant to this pull request? This may include screenshots, references, and/or implementation notes.

No.

Checklist

Please ensure the following tasks are completed before submitting this pull request.


@stdlib-js/reviewers

@kgryte
Copy link
Member

kgryte commented Feb 25, 2024

@Planeshifter Would you mind reviewing? You might have additional ideas regarding the keys of the output object.

@kgryte kgryte requested a review from Planeshifter February 25, 2024 01:07
@kgryte kgryte added Enhancement Issue or pull request for enhancing existing functionality. Needs Review A pull request which needs code review. TypeScript Issue involves or relates to TypeScript. labels Feb 25, 2024
@kgryte kgryte changed the title refactor: improve type declarations for group function using generics refactor: improve type declarations by using generics in utils/group Feb 25, 2024
Copy link
Contributor

@stdlib-bot stdlib-bot left a comment

Choose a reason for hiding this comment

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

👋 Hi there! 👋

And thank you for opening your first pull request! We will review it shortly. 🏃 💨

Copy link
Member

@Planeshifter Planeshifter left a comment

Choose a reason for hiding this comment

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

The type of the collection elements does not have to match the types of the group elements. For example, we could have a numeric array and a group array of strings denoting the group labels. So we shouldn't use the T generic for both collections.

In fact, I suggest we enforce that the groups collection groups should contain only values that are valid property keys

@rajutkarsh07
Copy link
Contributor Author

@Planeshifter I have updated the code

refactor: add type constraint for group labels in group function declaration
Copy link
Member

@Planeshifter Planeshifter left a comment

Choose a reason for hiding this comment

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

Two suggestions, then this should be ready to land; thanks!

@rajutkarsh07
Copy link
Contributor Author

@Planeshifter I have made the required changes

@Planeshifter
Copy link
Member

@rajutkarsh07 Great, thanks! Will merge after CI has passed.

@Planeshifter Planeshifter merged commit e971001 into stdlib-js:develop Mar 1, 2024
@rajutkarsh07 rajutkarsh07 deleted the groupType branch March 24, 2024 21:44
@Planeshifter Planeshifter removed the Needs Review A pull request which needs code review. label Mar 26, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Enhancement Issue or pull request for enhancing existing functionality. TypeScript Issue involves or relates to TypeScript.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[RFC]: improve type declarations for @stdlib/utils/group
4 participants