-
Notifications
You must be signed in to change notification settings - Fork 8
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 #125
Add non-spread overload for Result.all #125
Conversation
// 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.
jest.config.js
Outdated
'^.*\.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
Hey, I think this is a nice idea, thank you very much for this. I'll do a full review later but in the meantime please can you remove unrelated changes from this PR? (reformatting, whitespace, jest.config changes, anything else that I missed) |
08f3d0b
to
6141535
Compare
Done! Thank you @jstasiak. Had to wrestle with the editor to omit the whitespace changes. All tests pass now as well. |
The jest changes have been moved to #126 |
Thank you, I think this is a great addition. Can you update the documentation too? It's in |
440f751
to
f6035ce
Compare
f6035ce
to
a604ea8
Compare
Ok @jstasiak, how do those docs read for you? |
a604ea8
to
0cb8cb2
Compare
0cb8cb2
to
fc0bafd
Compare
Very nice, thank you |
Released in version 4.2.0 just now. |
Howdy! I'm bringing this PR over from the decidedly dead vultix/ts-results repo.
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, speaking from personal experience in an enterprise environment; the usage of
Result.all
via a spread array (Result.all(...myResults)
) grossly exceeds the usage ofResult.all
with multiple parameters. I'd imagine this is the same for others as well.This new behavior has been added as an overload of
Result.all
to offer backwards compatibility for those spreading arrays in, or passing each argument individually. Though based on the stack overflow issue mentioned above, I'd recommend users migrate from array spreading to just passing the array.