connectrpc / connect-query-es

TypeScript-first expansion pack for TanStack Query that gives you Protobuf superpowers.
https://connectrpc.com/docs/web/query/getting-started
Apache License 2.0
228 stars 15 forks source link

Add way to provider updater types to queryclient.setQueryData with createConnectQueryKey #391

Closed nickzelei closed 6 days ago

nickzelei commented 3 months ago

Hey all, I'm playing with the createConnectQueryKey and I'm wondering if there is a way to allow TS to better infer the return type when using it in conjunction with the tanstack queryclient.setQueryData.

It's able to infer the some of the types, but not all of them. Arguably the most important being the actual value that the cache is going to be updated to.

Screenshot below shows an example. TS is definitely inferring some of the types, but the updater is still set to unknown. It would be awesome if by passing in the query key if the updater could be set to the response type, in this case, GetAccountOnboardingConfigResponse

image
timostamm commented 3 months ago

I don't think TanStack's QueryClient.setQueryData - which we are using here - can infer data type from the key type. To enforce matching key and value, we'd have to provide our own API to set query data.

timostamm commented 6 days ago

Closing in favor of #390.