openapi-typescript icon indicating copy to clipboard operation
openapi-typescript copied to clipboard

`getQueryData` does not infer correct type from `client.queryOptions`

Open irsooti opened this issue 3 months ago • 2 comments

When using openapi-ts together with openapi-react-query, it seems that getQueryData does not correctly infer the type for the data associated with a query created via client.queryOptions.

Example:

const customersQueryOptions = client.queryOptions(‘get’, ‘/customers’, queryArguments);

const oldData = queryClient.getQueryData(customersQueryOptions.queryKey); 
//            ^ not inferred! oldData is `unknown`

Expected: oldData should have the same type as the data returned by the /customers endpoint.

Actual: oldData is not correctly typed — TypeScript does not infer the correct shape from the query options.

Proposal

It looks like the type information from queryOptions is not being propagated to the getQueryData (but also for setQueryData) method.
Would it be possible to make queryKey carry the full type context (like ReturnType or generics) so that getQueryData gets proper inference?

Extra

irsooti avatar Oct 14 '25 09:10 irsooti