neverthrow
neverthrow copied to clipboard
Add `toJSON` method for Result and AsyncResult
It would be really helpful to add a function toJSON for Result and AsyncResult that gets ride of functions (map, mapErr, unwrapOr...etc) and changes the isOk and isErr functions into boolean values. so the result object will be something like this.
type Obj<T> = {
isOk: boolean;
isErr: boolean;
value: T;
}
This may look useless but its really needed when it comes to using neverthrow with server actions since all the result would get serialized you cannot use functions especially isOk and isErr.
an example would look like this:
const serverAction = () => {
return ok({ env: 'action' })
}
The change won't be noticed by developers but it will allow developers too use neverthrow on server actions instead of relying on other ways or spend time debugging issues related to this.
I am more that happy making changes and filing a PR.