-
-
Notifications
You must be signed in to change notification settings - Fork 585
Open
Labels
enhancementNew feature or requestNew feature or requestopenapi-tsRelevant to the openapi-typescript libraryRelevant to the openapi-typescript library
Description
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
- I’m willing to open a PR (see CONTRIBUTING.md)
Metadata
Metadata
Assignees
Labels
enhancementNew feature or requestNew feature or requestopenapi-tsRelevant to the openapi-typescript libraryRelevant to the openapi-typescript library