orval-labs / orval

orval is able to generate client with appropriate type-signatures (TypeScript) from any valid OpenAPI v3 or Swagger v2 specification, either in yaml or json formats. 🍺
https://orval.dev
MIT License
3.18k stars 336 forks source link

Query: improve type-safety (like the queryOptions type-helper) #1671

Closed AmitBar2001 closed 3 weeks ago

AmitBar2001 commented 4 weeks ago

What are the steps to reproduce this issue?

  1. Generate a TanStack-Query client (react for example).
  2. Call a generated hook (useListPets() for example).
  3. Call queryClient.getQueryData / queryClient.setQueryData with the queryKey returned from the hook call.

What happens?

The return-type of queryClient.getQueryData is 'unknown'

image (added the lines of code to the basic react query sample)

What were you expecting to happen?

It's a missing feature, not a bug. I would love for it to be: The return-type of queryClient.getQueryData is 'PetsArray | undefined'.

Basically, I would like to match the behavior of the type-helper function 'queryOptions()' introduced in TanStack Query v5, specifically it's DataTag mechanism.

TanStack Query maintainer TkDodo explains all about it here: https://tkdodo.eu/blog/the-query-options-api#datatag

Any logs, error output, etc?

N/A - feature

Any other comments?

This would also help with queryClient.setQueryData type-safety, and type-safety of any future function consumer of TaggedQueryKey in TanStack Query.

What versions are you using?

System: OS: Windows 11 10.0.22631 CPU: (16) x64 12th Gen Intel(R) Core(TM) i7-1260P Memory: 4.66 GB / 15.73 GB npmPackages: @tanstack/react-query: ^5.0.0 => 5.39.0 msw: ^2.0.2 => 2.3.0 react: ^17.0.1 => 17.0.2