NextJS Output Typings
Quick question probably stupid, I learned about this library yesterday and completely migrated from Redux. However I noticed the types were a bit weird? Maybe it's intended but I can't find any documentation.
When returning fetched documents using a Mongoose model, the correct output type is displayed on the router. However when doing the
.useQuery()
it says the result is unknown
. (Images Attached)
Another problem I face is related to a potential solution I found to this problem, by casting a type to the response it fixes the empty object type. But now the types complex values get converted to string, which I see why this would happen because data is transmitted through JSON. Is there a Generic or some type I'm missing so I can correctly type function parameters?Solution:Jump to solution
Solution:
Follow This Guide: https://trpc.io/docs/server/data-transformers
Although the Client <--> Server data works just fine, a transformer is needed for correct typings... For some reason.
...
Data Transformers | tRPC
You are able to serialize the response data & input args. The transformers need to be added both to the server and the client.
1 Reply
Solution
Solution:
Follow This Guide: https://trpc.io/docs/server/data-transformers
Although the Client <--> Server data works just fine, a transformer is needed for correct typings... For some reason.
Maybe a bug?
Data Transformers | tRPC
You are able to serialize the response data & input args. The transformers need to be added both to the server and the client.