How to serialise and deserialise result types?
Opened this issue · 1 comments
plushdohn commented
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 commented
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