Skip to content

Wrong type in openapi-react-query when using select to transform data #1845

Closed
@HagenMorano

Description

@HagenMorano

Mind: This is a bug in openapi-react-query. There is no template for opening Bugs for the openapi-react-query package yet.

Description

The select transformer in the queryOptions of the useQuery method expects a value of type data as return value. The value should be transformable to an arbitrary value (and be inherited correctly). Example:

Cool:

$api.useQuery('get', '/pets/person', {},
  {
    select: (data) => data,
  }
);

Not cool:

$api.useQuery('get', '/pets/person', {},
  {
    select: (data) => data.age, // or any other value
  }
);

Reproduction

See the implementation at the bottom of fetchClient.ts in this Stackblitz.

Expected result

Arbitrary return values in the select method do not throw type errors. Furthermore, data should infer the type of the returned value of the select method (if set):

const { data } = $api.useQuery('get', '/pets/person', {},
  {
    select: (data) => data.age, // this shouldn't throw any type errors
  }
);

const str: number | undefined = data; // this shouldn't throw any type errors either as date.age is of type number and optional.

Metadata

Metadata

Assignees

Labels

PRs welcomePRs are welcome to solve this issue!bugSomething isn't workinggood first issueStraightforward problem, solvable for first-time contributors without deep knowledge of the projectopenapi-react-queryRelevant to openapi-react-query

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions