Result/Option infer any type when map.
I've been using the Result lib for some time, and its api it's really great, but the type inference has become a bit difficult when mapping over Result/option objects.
I've noticed that the any type is spreading because the
Err<E, T = any> and in the map definition don't pass the OutputValue to the Err type. Is there a reason for that? If I made this change, I would get the correct type inference.



7 Replies
It's aimed to match the API of Rust.. that's honestly the only reason.
@kyra 🩵🩷🤍🩷🩵 can you say more on this?
@Favna Just a update on this topic, i've noticed that the NPM package has different declaration file from the Github, but both point to the same version
2.7.2. I've download the github version and add to the project and the types are been inferred correctly.
The Github version is returning a Result type instead of the IfValue.

It was fixed 10months ago https://github.com/sapphiredev/utilities/commit/44fccf0029e31862a03d2097bb1585b3fc3df074 But the fix is not on NPM
:Thonk:
hm
guess we never released odd
release post will be up soon
Thanks @Favna , i'm also porting the
neverthrow implementation of safeTry to simulate Rust ? operator. I can open a PR if that is interesting to guys.
sure that would be great
I've open two PR's
1. Update types for Option types (missing from last fix) and for the method
Result.andThen.
https://github.com/sapphiredev/utilities/pull/918
2. Implementation of Rust's ? operator
https://github.com/sapphiredev/utilities/pull/917GitHub
feat: improve result and options types by feelsantiago · Pull Requ...
Update types from Option and Result.andThen to infer correct types.
GitHub
feat: add safeTry to emulate rust ? operator by feelsantiago · Pul...
This is a neverThrow.safeTry inspired implementation to simulate Rust&#39;s ? operator.
Usage Example
import { Result } from &#39;@sapphire/result&#39;;
const result = Result.safeTry(...