Using NeverThrow with "Use Server"
How does one return a funciton with the type of Result Async without the linter complaining that a "use server" file can "only export async functions. Add "async" to the function declaration or return a Promise"
I managed to do a hacky workaround by undoing NeverThrow's Result Async type, but this disbars you from using any of the other Result Async methods since it's seen as a normal promise.
I feels like I'm missing some type extension or should just modify the actual lint rules.
I've attached some code below outlining my current solution/predicament.
1 Reply
I don't think that's possible. With "use server" the exported functions are transformed into endpoints, they're no longer just "functions". Even if you got the linter working somehow. The result of the function is serialized and then deserialized on the client. You would simply loose the methods and all the niceties ResultAsync offers.
I don't think ResultAsync is thenable either, so you wouldn't even be getting the data in the client.
With Result not having public properties to access the value/error I don't even think that wrapped in a promise would work either.
If you get something in the client then good, just use Promise + Result. If you don't then just forget about using neverthrow to return results from endpoints and just return serializable objects