Closed ashishbairwa closed 5 months ago
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 useQuery
. Thanks!
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. For general questions, we recommend using StackOverflow or our discord server.
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