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
When using a custom fetch implementation with Orval, the generated client files produce types with any that trigger Biome linter warnings. This issue doesn't occur when using Orval's built-in fetch.
For reference, here's my custom fetch implementation:
constgetBody=async<T>(response: Response): Promise<T>=>{constcontentType=response.headers.get('content-type')if(contentType?.includes('application/json')){returnresponse.json()}if(contentType?.includes('application/pdf')){returnresponse.blob()asPromise<T>}returnresponse.text()asPromise<T>}constgetUrl=(contextUrl: string): string=>{constbaseUrl=process.env.NEXT_PUBLIC_API_BASE_URLconsturl=newURL(`${baseUrl}${contextUrl}`)constpathname=url.pathnameconstsearch=url.searchconstrequestUrl=newURL(`${baseUrl}${pathname}${search}`)returnrequestUrl.toString()}constgetHeaders=async(headers?: HeadersInit): Promise<HeadersInit>=>{// Add more headers here if neededreturn{
...headers,}}consthandleErrorResponse=async(response: Response): Promise<never>=>{// Handle errors nicely here}// Type definition for the request functiontypeCustomFetchFunction=<T>(url: string,init?: RequestInit)=>Promise<T>// The actual implementation with explicit typingexportconstcustomFetch: CustomFetchFunction=async<T>(url: string,init?: RequestInit): Promise<T>=>{constrequestUrl=getUrl(url)constrequestHeaders=awaitgetHeaders(init?.headers)constresponse=awaitfetch(requestUrl,{
...init,headers: requestHeaders,})// Handle 204 No Contentif(response.status===204){return{}asT}// Handle error responsesif(!response.ok){awaithandleErrorResponse(response)}constdata=awaitgetBody<T>(response)returndata}
Questions
How can I eliminate the any type in my custom fetch implementation?
Why doesn't this issue occur with Orval's built-in fetch?
Any insights or solutions would be greatly appreciated.
The text was updated successfully, but these errors were encountered:
Description
When using a custom fetch implementation with Orval, the generated client files produce types with
any
that trigger Biome linter warnings. This issue doesn't occur when using Orval's built-in fetch.Configuration
Current Orval configuration:
Problem
The generated client uses the following type definition:
This results in complex type definitions in the generated hooks:
Current Implementation
For reference, here's my custom fetch implementation:
Questions
any
type in my custom fetch implementation?Any insights or solutions would be greatly appreciated.
The text was updated successfully, but these errors were encountered: