orval is able to generate client with appropriate type-signatures (TypeScript) from any valid OpenAPI v3 or Swagger v2 specification, either in yaml or json formats. 🍺
No overload matches this call.
Overload 1 of 3, '(petId: string, options?: { query?: (Partial<UseQueryOptions<petResponse, Promise<Error>, petResponse, QueryKey>> & Pick<...>) | undefined; fetch?: RequestInit | undefined; } | undefined): UseQueryResult<...> & { ...; }', gave the following error.
Argument of type 'string | undefined' is not assignable to parameter of type 'string'.
Type 'undefined' is not assignable to type 'string'.
Overload 2 of 3, '(petId: string, options?: { query?: Partial<UseQueryOptions<petResponse, Promise<Error>, petResponse, QueryKey>> | undefined; fetch?: RequestInit | undefined; } | undefined): UseQueryResult<...> & { ...; }', gave the following error.
Argument of type 'string | undefined' is not assignable to parameter of type 'string'.
Type 'undefined' is not assignable to type 'string'.ts(2769)
endpoints.ts(137, 17): The call would have succeeded against this implementation, but implementation signatures of overloads are not externally visible.
Generated overloads:
export function usePet<
TData = Awaited<ReturnType<typeof pet>>,
TError = Promise<Error>,
>(
// Should be string | undefined | null
petId: string,
options: {
query: Partial<
UseQueryOptions<Awaited<ReturnType<typeof pet>>, TError, TData>
> &
Pick<
DefinedInitialDataOptions<
Awaited<ReturnType<typeof pet>>,
TError,
TData
>,
"initialData"
>;
fetch?: RequestInit;
},
): DefinedUseQueryResult<TData, TError> & { queryKey: QueryKey };
export function usePet<
TData = Awaited<ReturnType<typeof pet>>,
TError = Promise<Error>,
>(
// Should be string | undefined | null
petId: string,
options?: {
query?: Partial<
UseQueryOptions<Awaited<ReturnType<typeof pet>>, TError, TData>
> &
Pick<
UndefinedInitialDataOptions<
Awaited<ReturnType<typeof pet>>,
TError,
TData
>,
"initialData"
>;
fetch?: RequestInit;
},
): UseQueryResult<TData, TError> & { queryKey: QueryKey };
export function usePet<
TData = Awaited<ReturnType<typeof pet>>,
TError = Promise<Error>,
>(
// Should be string | undefined | null
petId: string,
options?: {
query?: Partial<
UseQueryOptions<Awaited<ReturnType<typeof pet>>, TError, TData>
>;
fetch?: RequestInit;
},
): UseQueryResult<TData, TError> & { queryKey: QueryKey };
/**
* @summary Info for a specific pet
*/
export function usePet<
TData = Awaited<ReturnType<typeof pet>>,
TError = Promise<Error>,
>(
// The actual implementation has the correct types
petId: string | undefined | null,
options?: {
query?: Partial<
UseQueryOptions<Awaited<ReturnType<typeof pet>>, TError, TData>
>;
fetch?: RequestInit;
},
): UseQueryResult<TData, TError> & { queryKey: QueryKey } {
const queryOptions = getPetQueryOptions(petId, options);
const query = useQuery(queryOptions) as UseQueryResult<TData, TError> & {
queryKey: QueryKey;
};
query.queryKey = queryOptions.queryKey;
return query;
}
What were you expecting to happen?
The optional parameter would be allowed in all overloads
Any other comments?
This PR added overloads to all hooks to allow for proper typing of the response when supplying initialData. However, these overloads don't consider the allParamsOptional option for the path parameters resulting in 3 function signatures that don't allow for undefined path parameters while the actual implementation does allow for it.
The problem is that these function overloads use the definition of the endpoint rather than the implementation and the allParamsOptional config setting only applies to the implementation of the endpoint's definition. However, the function overloads cannot use the implementation because the implementation also includes the default values which you cannot define in function overloads. We would need something that's in between the definition and implementation that does include the | undefined | null from the allParamsOptional setting but does not include the default parameters from the implementation.
What are the steps to reproduce this issue?
allParamsOptional
option in the configreact-query
clientOpenAPI sample spec:
orval.config.ts:
What happens?
You get a Typescript error:
Generated overloads:
What were you expecting to happen?
The optional parameter would be allowed in all overloads
Any other comments?
This PR added overloads to all hooks to allow for proper typing of the response when supplying
initialData
. However, these overloads don't consider theallParamsOptional
option for the path parameters resulting in 3 function signatures that don't allow forundefined
path parameters while the actual implementation does allow for it.The problem is that these function overloads use the
definition
of the endpoint rather than theimplementation
and theallParamsOptional
config setting only applies to theimplementation
of the endpoint's definition. However, the function overloads cannot use theimplementation
because theimplementation
also includes the default values which you cannot define in function overloads. We would need something that's in between thedefinition
andimplementation
that does include the| undefined | null
from theallParamsOptional
setting but does not include the default parameters from theimplementation
.What versions are you using?