Skip to content

Commit 44a683a

Browse files
fix(typescript-axios): add explicit return type to avoid TS2527 error
axios 1.7.5+ exports a unique symbol that TypeScript cannot infer through the generated createRequestFunction. Adding an explicit ': Promise<R>' return type on the inner arrow function and casting the result prevents TS from exposing the inaccessible symbol. Upstream fix: OpenAPITools/openapi-generator#24526 (not yet in v7.16.0). Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
1 parent d04e052 commit 44a683a

1 file changed

Lines changed: 3 additions & 2 deletions

File tree

generators/typescript-axios/templates/common.mustache

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -98,9 +98,10 @@ export const toPathString = function (url: URL) {
9898
return url.pathname + url.search + url.hash
9999
}
100100

101+
{{! Explicit return type annotation to avoid TS2527 with axios 1.7.5+ unique symbol}}
101102
export const createRequestFunction = function (axiosArgs: RequestArgs, globalAxios: AxiosInstance, BASE_PATH: string, configuration?: Configuration) {
102-
return <T = unknown, R = AxiosResponse<T>>(axios: AxiosInstance = globalAxios, basePath: string = BASE_PATH) => {
103+
return <T = unknown, R = AxiosResponse<T>>(axios: AxiosInstance = globalAxios, basePath: string = BASE_PATH): Promise<R> => {
103104
const axiosRequestArgs = {...axiosArgs.options, url: (axios.defaults.baseURL ? '' : configuration?.basePath ?? basePath) + axiosArgs.url};
104-
return axios.request<T, R>(axiosRequestArgs);
105+
return axios.request<T, R>(axiosRequestArgs) as Promise<R>;
105106
};
106107
}

0 commit comments

Comments
 (0)