Skip to content
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

feat(sum): improve type for list of booleans #143

Merged

Conversation

MarlonPassos-git
Copy link
Contributor

@MarlonPassos-git MarlonPassos-git commented Jul 29, 2024

Tip

The owner of this PR can publish a preview release by commenting /publish in this PR. Afterwards, anyone can try it out by running pnpm add radashi@pr<PR_NUMBER>.

Summary

In a Radash issue, there was a need to handle a list of boolean values. Therefore, I decided to implement a type adjustment to address this case.

Related issue, if any:

sodiray/radash#419

For any code change,

  • Related documentation has been updated, if needed
  • Related tests have been added or updated, if needed
  • Related benchmarks have been added or updated, if needed

Does this PR introduce a breaking change?

No

Bundle impact

Status File Size

@aleclarson
Copy link
Member

aleclarson commented Jul 29, 2024

You might want to do a git rebase origin/main -X theirs

Comment on lines 22 to 26
export function sum<T extends number>(array: readonly T[]): number
export function sum<T extends object>(
export function sum<T extends object | boolean>(
array: readonly T[],
fn: (item: T) => number,
): number
Copy link
Member

Choose a reason for hiding this comment

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

The old sum types were bad, so I'd suggest a more ambitious change:

export function sum(array: readonly number[]): number
export function sum<T>(
  array: readonly T[],
  fn: (item: T) => number,
): number

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I also prefer your suggestion. It doesn't limit the typing.

Copy link
Contributor Author

@MarlonPassos-git MarlonPassos-git Jul 29, 2024

Choose a reason for hiding this comment

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

Unfortunately, without removing the any I couldn't get typing to create a valid overload through TypeScript. But I think it improved a bit.

@MarlonPassos-git MarlonPassos-git changed the title Feat(sum) Improve type for list of booleans feat(sum): improve type for list of booleans Jul 29, 2024
@aleclarson aleclarson force-pushed the feat/sum-improve-bollean-types branch from a75f2e4 to d9280fa Compare August 6, 2024 23:27
@aleclarson aleclarson merged commit bfd9977 into radashi-org:main Aug 6, 2024
5 checks passed
aleclarson added a commit that referenced this pull request Aug 6, 2024
@aleclarson
Copy link
Member

I really appreciate your efforts recently. It'd be great to have you on the core team! Let me know if you'd like an invite. 👍

@MarlonPassos-git
Copy link
Contributor Author

@aleclarson Count me in! ✌️

Copy link

github-actions bot commented Aug 7, 2024

A new beta version 12.2.0-beta.7fb6e89 has been published to NPM. 🚀

To install:

The radashi@beta tag also includes this PR.

See the changes

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.

2 participants