2 ms·
Your problem there seems to mostly be that you tried to directly port it without any modifications, and your code is actually incorrect in some places. For exam
by phiresky 7y ago
Your problem there seems to mostly be that you tried to directly port it without any modifications, and your code is actually incorrect in some places. For example, if you implemented Result<T, E> as a single class that had a `if(this.is_ok()) ...; else ...` it would work fine without any type assertions or any anywhere.
As it is, Ok only depends on T and Err only depends on E, so why do you have them depend on both?
One problem is that TS does not want to merge unionized function signatures like this:
map: (<U>(fn: (arg: "yep") => U) => Ok<U>) | (<U>(fn: (arg: any) => U) => Result<U, "nope">)
This can be mostly fixed by removing arguments that you don't need.
I couldn't figure out .map_or_else, but .map().or_else() works.
Admittedly, with this way you can get an output of Ok<a> | Ok<b> from some functions, but I don't know where that would be a problem (still fully type checked, you would just get the expected error further outside.
Here's a updated gist: https://gist.github.com/phiresky/621f8d8ed6eb00c9a0ddb47217eae38a https://gist.github.com/phiresky/621f8d8ed6eb00c9a0ddb47217e...