Closed
Description
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.