-
Notifications
You must be signed in to change notification settings - Fork 2.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Typeguard for useQuery fails when the queryOptions passed using spread operator #11874
Comments
Hi @ashishbairwa 👋🏻 I'm a middling TypeScript practitioner at best, but I think you're seeing a default behavior of TypeScript. Here's a TS Playground demonstrating the same behavior without Apollo Client: That said, I'll check with the team to see if it's possible/advisable to implement some kind of utility type for this use case and get back to you! |
Also, I'm not certain your stackblitz or code snippet is entirely illustrative of the issue - the former is in JavaScript and the latter doesn't use a spread operator, so I tried to recreate this in our Spotify Showcase from your description. |
Hi @ashishbairwa - we've discussed some pros and cons and won't be moving forward with attempting to narrow the types in this way. Doing so could be backwards-incompatible for some users, and we don't see a straightforward way to implement such an abstraction without a considerable amount of work. In the interim I recommend adding the relevant type annotations to the objects that you spread into |
Do you have any feedback for the maintainers? Please tell us by taking a one-minute survey. Your responses will help us understand Apollo Client usage and allow us to serve you better. |
This issue has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs. |
Issue Description
When we pass query options in spread operator, it escapes type checking which results in unexpected issues and behaviour
Sample query use which fails typechecking:
Link to Reproduction
https://stackblitz.com/edit/react-apollo-client-demo-oldapm?file=src%2FCountryDetail.js
Reproduction Steps
@apollo/client
version3.6.6
The text was updated successfully, but these errors were encountered: