-
Notifications
You must be signed in to change notification settings - Fork 71
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
Add non-spread overload for Result.all #86
Add non-spread overload for Result.all #86
Conversation
'^.*\.ts$': ['ts-jest', { | ||
tsconfig: 'test/tsconfig.json' | ||
}] | ||
} |
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.
This silences the warnings that global ts-jest configuration is deprecated
"typescript": "^4.2" | ||
"ts-jest": "^29.1.2", | ||
"tslib": "^2.6.2", | ||
"typescript": "^5.4" |
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.
Bumping to typescript 5.X allows the use of const type params.
// Utility types | ||
type Head<T extends any[]> = T extends [any, ...infer R] ? | ||
T extends [...infer F, ...R] ? F : never : never | ||
type Tail<T extends any[]> = T extends [any, ...infer R] ? R : never |
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.
These could likely be removed since the arrays I'm parsing above are typed as any[]. I could just as easily type the arguments as arg0: T[0] | T, argN: ...T but using these types are technically truer to what's going on.
expect(all1Array).toMatchResult(Ok([3, true])); | ||
eq<typeof all1Array, Result<[number, boolean], never>>(true); | ||
|
||
const all2 = Result.all(err0, err1); |
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.
Corrected the naming indexes being off for all2 and onward
Hey @kevinsimper! Looks like you're somewhat active on this repo. Mind taking a peek at this? |
Or @vultix are you still around? |
I'd like to have #81 merged in as well since I'm fighting errors with |
This PR adds non-spread variants of
Result.all
andResult.any
which should be preferred over the parameter spread variants. For instances whereResult.all
orResult.any
are invoked with very large arrays, the spread operation could lead to stack overflows. Additionally, though heavy usage of Result.all in an enterprise enviornment, usage of Result.all with an array (Result.all(...myResultArray)
) grossly exceeds the times whereResult.all
is used with multiple named results passed as individual arguments.To accurately support the inferred types from Result.all and Result.any, const type parameters were used which requires bumping up to at least Typescript 5.0.
This PR solves #85