tRPCttRPC
Powered by
KarolK
tRPC•2y ago•
2 replies
Karol

Using output validator breaks query return type inference on react query

Hi! I am not sure whether this is expected and whether there is some way to fix that but here it goes. I am using trpc (up to date 11 beta) on nextjs set up according to trpc website guide and use react-query integration as presented on screens. When I skip
.output([some validator here])
.output([some validator here])
on procedure definition, return types are correctly inferred and
data
data
is as presented on screen. However when I add output validation (see other screen), the returned
data
data
type is set to
unknown
unknown
. Am I missing something somewhere? I want to use output validator and still have benefit of using types on my frontend. I have not found any issue or mention of similar issue anywhere so maybe I am doing something wrong there. Appreciate the help!
Screenshot_2024-02-08_at_12.20.15.png
Screenshot_2024-02-08_at_12.19.57.png
Solution
Ok I resolved my issue myself, it's that I did not have strict null checks turned on on my component directory since I haven't managed to turn it on everywhere yet. When I turn it on, types are inferred correct. Case closed.
Jump to solution
tRPCJoin
Move Fast & Break Nothing. End-to-end typesafe APIs made easy.
5,015Members
Resources
Was this page helpful?

Similar Threads

Recent Announcements

Similar Threads

Output validator for Async generators on a streaming procedure using Zod
fjjfjfjFfjjfjfj / ❓-help
6mo ago
return type of a query endpoint
rustclanRrustclan / ❓-help
3y ago
Type mismatch with queryClient prop of @trpc/react-query
MadyanMMadyan / ❓-help
15mo ago
Complex type inference on router outputs?
ianIian / ❓-help
2y ago