Using Neverthrow with functions
error image attached.
example backend code:
I imagine its just because Convex can't serialize the Neverthrow Result/Ok object to JSON, is there a clean workaround to this?

7 Replies
oh, and what's the result from 'ResultAsync.fromPromise'? either string or json, correct?
you might need to give the query a return type
I am asking because there's a detatched "Ok" before the value
yeah, I think Ok is a generic class or maybe an object
ResultAsync<T, E> is just Promise<Ok<T> | Err<E>>
Yep, now this makes sense, this si not a valid convex type
to by pass this, give the query a return type, using the
returnsoh okay, that makes sense
could I do
returns: v.any() as Validator<Result<...>> or would that breakI remember there's a way to make it a valid convex type, I just can't remember how
I'd chat gpt it
okay
thx!
You can use regular validators, you just need to unwrap the result inside of your convex function before you return: https://github.com/supermacro/neverthrow/wiki/Accessing-The-Value-Inside-A-Result
GitHub
Accessing The Value Inside A Result
Type-Safe Errors for JS & TypeScript. Contribute to supermacro/neverthrow development by creating an account on GitHub.