-
Notifications
You must be signed in to change notification settings - Fork 33
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
feat(sum): improve type for list of booleans #143
Conversation
You might want to do a |
src/number/sum.ts
Outdated
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 |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
…143) Co-authored-by: Alec Larson <[email protected]>
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. 👍 |
@aleclarson Count me in! ✌️ |
A new beta version To install: pnpm add [email protected] The ![]() |
Tip
The owner of this PR can publish a preview release by commenting
/publish
in this PR. Afterwards, anyone can try it out by runningpnpm 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,
Does this PR introduce a breaking change?
No
Bundle impact