Skip to content

getQueryData does not infer correct type from client.queryOptions #2492

@irsooti

Description

@irsooti

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or requestopenapi-tsRelevant to the openapi-typescript library

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions