Heterogeneous `combine` typing
See original GitHub issueHi.
With my understanding, only typing stops combine
currently from working with heterogeneous Results, implementation looks ready for them.
I just prepared types for combine
that works for Result
of many types, at least in my tests. Could it be useful for the library?
It will only works for TS 4.0+.
declare function combine<T extends Result<unknown, unknown>[]>(
resultList: [...T]
): CombineResult<T, T>;
type CombineResult<T extends unknown[], U extends unknown[]> = T extends [
infer Element,
...(infer Rest)
]
? Element extends Err<unknown, infer ErrH>
? Element
: CombineResult<Rest, U>
: Ok<
{ [Index in keyof U]: U[Index] extends Ok<infer OkElement, unknown> ? OkElement : never },
unknown
>;
Issue Analytics
- State:
- Created 3 years ago
- Comments:19 (11 by maintainers)
Top Results From Across the Web
Homogeneous vs. Heterogeneous Mixtures — A Comparison
Mixtures are made of two or more substances that are not chemically combined. Heterogeneous mixtures are randomly mixed. Homogeneous mixtures are uniform.
Read more >Homogeneous and Heterogeneous Mixture | Chemistry
In this animated lecture, I will teach you about homogeneous mixture and heterogeneous mixture.
Read more >Homogeneous vs Heterogeneous Mixtures - Diffen
The individual components in a mixture retain their identity. Mixtures are of two types: homogeneous and heterogeneous.
Read more >Chemical Mixtures
A mixture is made when two or more substances are combined, but they are not combined chemically. There are two main categories of...
Read more >Homogeneous and Heterogeneous Mixtures - CK-12
A heterogeneous mixture consists of two or more phases. When oil and water are combined, they do not mix evenly, but instead form...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
So this approach did indeed work. Check out the implementation based on the most recent commit to the project:
https://github.com/supermacro/neverthrow/blob/cfd12a9af796b11426f9426fa94795912f103b77/src/utils.ts
I am going to continue working on
neverthrow
stuff and then post a release once I am done (end of day today).Also I will keep this issue open to accept feedback on the current implementation on heterogeneous types.
Closing this issue, but as always feel free to open a new issue if there’s something you want to discuss / improve / provide feedback on!