Skip to content

Commit 849a332

Browse files
PicazsooCopilot
andauthored
fix(typescript-axios): resolve TS2527 inaccessible unique symbol error (#24526)
* fix(typescript-axios): resolve TS2527 inaccessible unique symbol error createRequestFunction's returned arrow function lacked an explicit return-type annotation. With axios >=1.19 (peer dep bumped to ^1.18.0 in b0670e2), AxiosInstance.request<T, R>() defaults R to a non-exported branded type backed by an unexported unique symbol, and its return type is a conditional that only collapses once R is concrete. Since our generic R stays unresolved through the call, TypeScript must reference the inaccessible symbol when inferring the exported function's type, causing TS2527. Fix: annotate the arrow function with an explicit Promise<R> return type and cast axios.request<T, R>(...)'s result with `as Promise<R>` to satisfy the assignability check. Applied to the common.mustache template and regenerated the 15 affected typescript-axios common.ts samples to match. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> * update samples --------- Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
1 parent 248d105 commit 849a332

16 files changed

Lines changed: 32 additions & 32 deletions

File tree

‎modules/openapi-generator/src/main/resources/typescript-axios/common.mustache‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -134,8 +134,8 @@ export const toPathString = function (url: URL) {
134134
}
135135

136136
export const createRequestFunction = function (axiosArgs: RequestArgs, globalAxios: AxiosInstance, BASE_PATH: string, configuration?: Configuration) {
137-
return <T = unknown, R = AxiosResponse<T>>(axios: AxiosInstance = globalAxios, basePath: string = BASE_PATH) => {
137+
return <T = unknown, R = AxiosResponse<T>>(axios: AxiosInstance = globalAxios, basePath: string = BASE_PATH): Promise<R> => {
138138
const axiosRequestArgs = {...axiosArgs.options, url: (axios.defaults.baseURL ? '' : configuration?.basePath ?? basePath) + axiosArgs.url};
139-
return axios.request<T, R>(axiosRequestArgs);
139+
return axios.request<T, R>(axiosRequestArgs) as Promise<R>;
140140
};
141141
}

‎samples/client/echo_api/typescript-axios/build/common.ts‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -120,8 +120,8 @@ export const toPathString = function (url: URL) {
120120
}
121121

122122
export const createRequestFunction = function (axiosArgs: RequestArgs, globalAxios: AxiosInstance, BASE_PATH: string, configuration?: Configuration) {
123-
return <T = unknown, R = AxiosResponse<T>>(axios: AxiosInstance = globalAxios, basePath: string = BASE_PATH) => {
123+
return <T = unknown, R = AxiosResponse<T>>(axios: AxiosInstance = globalAxios, basePath: string = BASE_PATH): Promise<R> => {
124124
const axiosRequestArgs = {...axiosArgs.options, url: (axios.defaults.baseURL ? '' : configuration?.basePath ?? basePath) + axiosArgs.url};
125-
return axios.request<T, R>(axiosRequestArgs);
125+
return axios.request<T, R>(axiosRequestArgs) as Promise<R>;
126126
};
127127
}

‎samples/client/others/typescript-axios/with-separate-models-and-api-inheritance/common.ts‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -120,8 +120,8 @@ export const toPathString = function (url: URL) {
120120
}
121121

122122
export const createRequestFunction = function (axiosArgs: RequestArgs, globalAxios: AxiosInstance, BASE_PATH: string, configuration?: Configuration) {
123-
return <T = unknown, R = AxiosResponse<T>>(axios: AxiosInstance = globalAxios, basePath: string = BASE_PATH) => {
123+
return <T = unknown, R = AxiosResponse<T>>(axios: AxiosInstance = globalAxios, basePath: string = BASE_PATH): Promise<R> => {
124124
const axiosRequestArgs = {...axiosArgs.options, url: (axios.defaults.baseURL ? '' : configuration?.basePath ?? basePath) + axiosArgs.url};
125-
return axios.request<T, R>(axiosRequestArgs);
125+
return axios.request<T, R>(axiosRequestArgs) as Promise<R>;
126126
};
127127
}

‎samples/client/petstore/typescript-axios/builds/composed-schemas/common.ts‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -120,8 +120,8 @@ export const toPathString = function (url: URL) {
120120
}
121121

122122
export const createRequestFunction = function (axiosArgs: RequestArgs, globalAxios: AxiosInstance, BASE_PATH: string, configuration?: Configuration) {
123-
return <T = unknown, R = AxiosResponse<T>>(axios: AxiosInstance = globalAxios, basePath: string = BASE_PATH) => {
123+
return <T = unknown, R = AxiosResponse<T>>(axios: AxiosInstance = globalAxios, basePath: string = BASE_PATH): Promise<R> => {
124124
const axiosRequestArgs = {...axiosArgs.options, url: (axios.defaults.baseURL ? '' : configuration?.basePath ?? basePath) + axiosArgs.url};
125-
return axios.request<T, R>(axiosRequestArgs);
125+
return axios.request<T, R>(axiosRequestArgs) as Promise<R>;
126126
};
127127
}

‎samples/client/petstore/typescript-axios/builds/default/common.ts‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -120,8 +120,8 @@ export const toPathString = function (url: URL) {
120120
}
121121

122122
export const createRequestFunction = function (axiosArgs: RequestArgs, globalAxios: AxiosInstance, BASE_PATH: string, configuration?: Configuration) {
123-
return <T = unknown, R = AxiosResponse<T>>(axios: AxiosInstance = globalAxios, basePath: string = BASE_PATH) => {
123+
return <T = unknown, R = AxiosResponse<T>>(axios: AxiosInstance = globalAxios, basePath: string = BASE_PATH): Promise<R> => {
124124
const axiosRequestArgs = {...axiosArgs.options, url: (axios.defaults.baseURL ? '' : configuration?.basePath ?? basePath) + axiosArgs.url};
125-
return axios.request<T, R>(axiosRequestArgs);
125+
return axios.request<T, R>(axiosRequestArgs) as Promise<R>;
126126
};
127127
}

‎samples/client/petstore/typescript-axios/builds/es6-target/common.ts‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -120,8 +120,8 @@ export const toPathString = function (url: URL) {
120120
}
121121

122122
export const createRequestFunction = function (axiosArgs: RequestArgs, globalAxios: AxiosInstance, BASE_PATH: string, configuration?: Configuration) {
123-
return <T = unknown, R = AxiosResponse<T>>(axios: AxiosInstance = globalAxios, basePath: string = BASE_PATH) => {
123+
return <T = unknown, R = AxiosResponse<T>>(axios: AxiosInstance = globalAxios, basePath: string = BASE_PATH): Promise<R> => {
124124
const axiosRequestArgs = {...axiosArgs.options, url: (axios.defaults.baseURL ? '' : configuration?.basePath ?? basePath) + axiosArgs.url};
125-
return axios.request<T, R>(axiosRequestArgs);
125+
return axios.request<T, R>(axiosRequestArgs) as Promise<R>;
126126
};
127127
}

‎samples/client/petstore/typescript-axios/builds/test-petstore/common.ts‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -120,8 +120,8 @@ export const toPathString = function (url: URL) {
120120
}
121121

122122
export const createRequestFunction = function (axiosArgs: RequestArgs, globalAxios: AxiosInstance, BASE_PATH: string, configuration?: Configuration) {
123-
return <T = unknown, R = AxiosResponse<T>>(axios: AxiosInstance = globalAxios, basePath: string = BASE_PATH) => {
123+
return <T = unknown, R = AxiosResponse<T>>(axios: AxiosInstance = globalAxios, basePath: string = BASE_PATH): Promise<R> => {
124124
const axiosRequestArgs = {...axiosArgs.options, url: (axios.defaults.baseURL ? '' : configuration?.basePath ?? basePath) + axiosArgs.url};
125-
return axios.request<T, R>(axiosRequestArgs);
125+
return axios.request<T, R>(axiosRequestArgs) as Promise<R>;
126126
};
127127
}

‎samples/client/petstore/typescript-axios/builds/with-complex-headers/common.ts‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -120,8 +120,8 @@ export const toPathString = function (url: URL) {
120120
}
121121

122122
export const createRequestFunction = function (axiosArgs: RequestArgs, globalAxios: AxiosInstance, BASE_PATH: string, configuration?: Configuration) {
123-
return <T = unknown, R = AxiosResponse<T>>(axios: AxiosInstance = globalAxios, basePath: string = BASE_PATH) => {
123+
return <T = unknown, R = AxiosResponse<T>>(axios: AxiosInstance = globalAxios, basePath: string = BASE_PATH): Promise<R> => {
124124
const axiosRequestArgs = {...axiosArgs.options, url: (axios.defaults.baseURL ? '' : configuration?.basePath ?? basePath) + axiosArgs.url};
125-
return axios.request<T, R>(axiosRequestArgs);
125+
return axios.request<T, R>(axiosRequestArgs) as Promise<R>;
126126
};
127127
}

‎samples/client/petstore/typescript-axios/builds/with-fake-endpoints-models-for-testing-with-http-signature/common.ts‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -120,8 +120,8 @@ export const toPathString = function (url: URL) {
120120
}
121121

122122
export const createRequestFunction = function (axiosArgs: RequestArgs, globalAxios: AxiosInstance, BASE_PATH: string, configuration?: Configuration) {
123-
return <T = unknown, R = AxiosResponse<T>>(axios: AxiosInstance = globalAxios, basePath: string = BASE_PATH) => {
123+
return <T = unknown, R = AxiosResponse<T>>(axios: AxiosInstance = globalAxios, basePath: string = BASE_PATH): Promise<R> => {
124124
const axiosRequestArgs = {...axiosArgs.options, url: (axios.defaults.baseURL ? '' : configuration?.basePath ?? basePath) + axiosArgs.url};
125-
return axios.request<T, R>(axiosRequestArgs);
125+
return axios.request<T, R>(axiosRequestArgs) as Promise<R>;
126126
};
127127
}

‎samples/client/petstore/typescript-axios/builds/with-interfaces-and-with-single-request-param/common.ts‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -120,8 +120,8 @@ export const toPathString = function (url: URL) {
120120
}
121121

122122
export const createRequestFunction = function (axiosArgs: RequestArgs, globalAxios: AxiosInstance, BASE_PATH: string, configuration?: Configuration) {
123-
return <T = unknown, R = AxiosResponse<T>>(axios: AxiosInstance = globalAxios, basePath: string = BASE_PATH) => {
123+
return <T = unknown, R = AxiosResponse<T>>(axios: AxiosInstance = globalAxios, basePath: string = BASE_PATH): Promise<R> => {
124124
const axiosRequestArgs = {...axiosArgs.options, url: (axios.defaults.baseURL ? '' : configuration?.basePath ?? basePath) + axiosArgs.url};
125-
return axios.request<T, R>(axiosRequestArgs);
125+
return axios.request<T, R>(axiosRequestArgs) as Promise<R>;
126126
};
127127
}

0 commit comments

Comments
 (0)