You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
useQuery select callback parameter is inferred as unknown instead of endpoint response type #2852
useQuery does not correctly infer the OpenAPI response type for the select callback.
The endpoint response type is available from the generated OpenAPI paths type, but inside select, the callback parameter is inferred as unknown. Because of this, mapper functions have to accept unknown and manually cast/narrow the response.
Package versions:
openapi-react-query: 0.5.4
openapi-fetch: 0.17.0
@tanstack/react-query: 5.100.9
typescript: 5.x
Example actual behavior:
functionmapAdminRolesListResponse(response: unknown): DashboardRolesListResponse{// Required workaround because select does not infer the real endpoint response type.}
Example errorshape:
Type'(response: RolesResponse) => DashboardRolesListResponse'isnotassignabletotype'(data: unknown) => DashboardRolesListResponse'.Type'unknown'isnotassignabletotype'RolesResponse'.
### Reproduction**Reproduction**```md```tsimport{keepPreviousData}from"@tanstack/react-query";importcreateFetchClientfrom"openapi-fetch";importcreateClientfrom"openapi-react-query";importtype{paths}from"./openapi";constfetchClient=createFetchClient<paths>({baseUrl: "",});const$api=createClient(fetchClient);typeRolesResponse=paths["/admin/roles"]["get"]["responses"][200]["content"]["application/json"];typeDashboardRolesListResponse={items: unknown[];};functionmapAdminRolesListResponse(response: RolesResponse): DashboardRolesListResponse{return{items: response.data.data,};}functionuseRolesQuery(){return$api.useQuery("get","/admin/roles",{params: {header: {Accept: "application/json",},},},{placeholderData: keepPreviousData,select: mapAdminRolesListResponse,});}
### Expectedresult**Expectedresult**```mdThe `select` callback should infer the response data type for the selected method/path.For this call:```ts$api.useQuery("get","/admin/roles",init,{select: mapAdminRolesListResponse,});
### Extra-[]I’mwillingtoopenaPR(see[CONTRIBUTING.md](https://github.com/openapi-ts/openapi-typescript/blob/main/packages/openapi-react-query/CONTRIBUTING.md))
Activity