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.
No description
No description
No description
No description
7 Replies
Favna
Favna2w ago
It's aimed to match the API of Rust.. that's honestly the only reason. @kyra 🩵🩷🤍🩷🩵 can you say more on this?
Merovinger
MerovingerOP2w ago
@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.
No description
No description
Favna
Favna2w ago
:Thonk: hm guess we never released odd release post will be up soon
Merovinger
MerovingerOP2w ago
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.
No description
Favna
Favna2w ago
sure that would be great
Merovinger
MerovingerOP2w ago
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/917
GitHub
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&amp;#39;s ? operator. Usage Example import { Result } from &amp;#39;@sapphire/result&amp;#39;; const result = Result.safeTry(...

Did you find this page helpful?