react-query-swagger
react-query-swagger copied to clipboard
Inconsistent result types between dto and raw primitive parameters
Hey!
I have a swagger that returns a file, which is generated as a Blob
type in react-query-swagger
.
I wanted to create URL.createObjectURL
out of it in the select
option.
These are the type definitions that are generated:
export function useAQuery<TSelectData = Types.FileResponse, TError = unknown>(dto: AQueryParameters, options?: Omit<UseQueryOptions<Types.FileResponse, TError, TSelectData>, 'queryKey'>): UseQueryResult<TSelectData, TError>;
/**
* Get A
* @return Success
*/
export function useAQuery<TSelectData = Types.FileResponse, TError = unknown>(a: string, b: string, options?: Omit<UseQueryOptions<TSelectData, TError, TSelectData>, 'queryKey'>): UseQueryResult<TSelectData, TError>;
As u can see the UseQueryOptions with DTO uses Types.FileResponse
as hardcoded value for the TQueryFnData
in UseQueryOptions
(which is correct I believe), while the type definition with primitive parameters use TSelectData
.
That breaks a case when we want to override select
function passed as an option
.
DTO works:
const result= Query.useAQuery({a: 'a', b: 'b'}, {
select: (blob) => URL.createObjectURL(blob.data)
});
Expanded version throws an error:
TS2322: Type (blob: FileResponse) => string is not assignable to type (data: FileResponse) => FileResponse
Type string is not assignable to type FileResponse
const result = Query.useAQuery('a', 'b', {
select: (blob) => URL.createObjectURL(blob.data)
});
Let me know if that is intended behavior and I'm missing something or if that's a bug. I can contribute if that's a bug.
Cheers.