Skip to content

Inconsistent result types between dto and raw primitive parameters #47

Description

@rafal-zelek

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.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions