You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I've been trying to create a queryFn that reads data from another query and returns data derived from that "external" data.
Here's an example: I have a getPosts query that returns a list of posts. My backend is missing an endpoint for getting a specific post, so I want to add a getPost query that reads data from getPosts, filters by its arg, and returns a result (or undefined). Something as simple as this.
The problem is that the entire myApi becomes any when I return the post. However, if I return undefined or hardcode the result, everything is typed as expected. And when myApi is any, everything else in the application is no longer typed.
Alternatively, I can create a custom hook that uses useGetPostsQuery under the hood. But I was wondering if the above could work or if I am doing something wrong. 🙄
Thanks! 🙏
The text was updated successfully, but these errors were encountered:
yes, this creates circular type inference and TS bails out. the easiest way to avoid it is to manually annotate the type for data so it doesn't need to be inferred. const data: Post | undefined =
Hi there 👋 ,
I've been trying to create a
queryFn
that reads data from another query and returns data derived from that "external" data.Here's an example: I have a
getPosts
query that returns a list of posts. My backend is missing an endpoint for getting a specific post, so I want to add agetPost
query that reads data fromgetPosts
, filters by its arg, and returns a result (or undefined). Something as simple as this.The problem is that the entire
myApi
becomesany
when I return the post. However, if I returnundefined
or hardcode the result, everything is typed as expected. And whenmyApi
isany
, everything else in the application is no longer typed.Alternatively, I can create a custom hook that uses
useGetPostsQuery
under the hood. But I was wondering if the above could work or if I am doing something wrong. 🙄Thanks! 🙏
The text was updated successfully, but these errors were encountered: