Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to serialise and deserialise result types? #613

Open
plushdohn opened this issue Nov 14, 2024 · 1 comment
Open

How to serialise and deserialise result types? #613

plushdohn opened this issue Nov 14, 2024 · 1 comment

Comments

@plushdohn
Copy link

I'm using neverthrow in the context of a full-stack app with typed RPCs. I'd like to be able to handle on the frontend the Result's that the backend returns, except they aren't serialisable because they contain functions.

Even if functions get stripped by a framework and only valid JSON is sent over the wire, I don't know how to recreate the respective Result on the frontend. Is there an API like fromSerialized(result)? Is this an intended use-case for neverthrow?

@janglad
Copy link

janglad commented Nov 18, 2024

It's not super difficult to implement an "intermediary" result type that can be serialised, I did this here with ActionResult.

https://github.com/janglad/safe-fn/blob/main/packages/safe-fn/src/result.ts

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants