ResultAsync is not a valid async function return type
See original GitHub issueAfter a lot of research into error handling in TypeScript, I’ve pretty much settled on this library as being the best option for our use. However, I am running into a major blocker. My existing codebase is built using async functions and await, but after converting the return type of a method from a Promise<something> to ResultAsync<something, someError>, the compiler complains that
Type 'typeof ResultAsync' is not a valid async function return type in ES5/ES3 because it does not refer to a Promise-compatible constructor value.
I am targeting ES5 in my tsconfig, because this is going to run in a browser, but it doesn’t make sense to me that it would not be promise compatible. This seems very basic so I figure I must be missing something here; is there a config option or something I may be overlooking? For the record, I’m using neverthrow 3.1.2.
As an example, even this basic method throws an error:
public async testAsync(): ResultAsync<string, Error> { return okAsync("Hello world!"); }
Issue Analytics
- State:
- Created 3 years ago
- Comments:12 (5 by maintainers)
Top GitHub Comments
Combining heterogeneous Results or ResultAsyncs has been on my todo-list for a while. In lieu of this missing functionality in neverthrow, this is how you could do it:
The
combine
function already does work for heterogeneous lists if you ran this code in javascript. The limitation right now is one of a simplified type definition - which forces you to only work on homogeneous lists in typescript only.Proof: https://repl.it/@gDelgado14/heterogeneous-combine
So what you can do for now is provide typecasts on
combine
function invocations:If you want to get really fancy (which is what I have to implement anyways when I do get around to doing this) is to provide function overloads for all the various invocations of
combine
(just like howPromise.all
is implemented in typescript)If both
func1()
andfunc2()
returnResultAsync
types that you need to compare, I would create aResultAsync
that has them both and then operate the comparison.