wleistra
wleistra2y ago

Type issue react query with enabled.

We migrate to trpc and using @tanstack/react-query directly to the trpc syntax of trpc.procedureName.useQuery(). Previously TypeScript understood that if an input like { id: string } to the useQuery was possibly null or undefined (because it comes from useParams() react-router hook for example) and the option on the useQuery was set to { enabled: !!id } that by the time the call was made id would indeed be a string. Now that we migrated to using trpc TS errors out and expects us to do silly things like { id: string ?? '' }. I would love to get the old behavior back.
2 Replies
Nick
Nick2y ago
You can set your input type to permit undefined? It's fully in your control what types are demanded there
wleistra
wleistra2y ago
Yes ofcourse I can do that. Except that it is mandatory to have the input to get a return from the server. I was just pointing out that seemingly the same library used in two different ways gives different type check results which I find strange.