Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(openapi-react-query): correctly infer select return value #2105

Conversation

HagenMorano
Copy link
Contributor

Changes

Resolves #1845 #1949

How to Review

See added test. When adding the select option, useQuery and useSuspenseQuery now infers the correct type when using the select transformer.

Example:

client.useQuery(
  "get",
  "/string-array",
  {},
  {
    select: () => 1, // resolves to type number
  },
),
client.useQuery(
  "get",
  "/string-array",
  {},
  {
    select: (data) => [data], // resolves to type `data[]`
  },
),
client.useQuery("get","/string-array") // still infers correct data (no change)

Checklist

  • Unit tests updated

@HagenMorano HagenMorano requested a review from a team as a code owner January 20, 2025 11:03
@HagenMorano HagenMorano requested a review from kerwanp January 20, 2025 11:03
Copy link

changeset-bot bot commented Jan 20, 2025

🦋 Changeset detected

Latest commit: 373427b

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
openapi-react-query Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

Copy link

netlify bot commented Jan 20, 2025

👷 Deploy request for openapi-ts pending review.

Visit the deploys page to approve it

Name Link
🔨 Latest commit 373427b

@kerwanp
Copy link
Contributor

kerwanp commented Jan 21, 2025

Looks really good to me, thanks for the contrib!

Could you add a patch changeset so I can merge this?

@HagenMorano HagenMorano force-pushed the correctly-inherit-type-in-react-query-select branch from 785174d to b42f008 Compare January 22, 2025 09:13
@HagenMorano
Copy link
Contributor Author

HagenMorano commented Jan 22, 2025

Not sure if I did the changeset correctly - added it via pnpm changeset

@HagenMorano HagenMorano force-pushed the correctly-inherit-type-in-react-query-select branch from b42f008 to 373427b Compare January 22, 2025 09:20
Copy link
Contributor

@kerwanp kerwanp left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🚀 Thanks a lot!

@kerwanp kerwanp merged commit af0e72f into openapi-ts:main Jan 22, 2025
8 checks passed
@openapi-ts-bot openapi-ts-bot mentioned this pull request Jan 22, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Wrong type in openapi-react-query when using select to transform data
2 participants