Skip to content

fix(typescript-axios): resolve TS2527 inaccessible unique symbol error - #24526

Open
Picazsoo wants to merge 3 commits into
OpenAPITools:masterfrom
Picazsoo:bugfix/typescript-axios-createRequestFunction
Open

fix(typescript-axios): resolve TS2527 inaccessible unique symbol error#24526
Picazsoo wants to merge 3 commits into
OpenAPITools:masterfrom
Picazsoo:bugfix/typescript-axios-createRequestFunction

Conversation

@Picazsoo

@Picazsoo Picazsoo commented Jul 30, 2026

Copy link
Copy Markdown
Contributor

fixes #24523

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 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.

PR checklist

  • Read the contribution guidelines.
  • Run the following to build the project and update samples:
    ./mvnw clean package || exit
    ./bin/generate-samples.sh ./bin/configs/*.yaml || exit
    ./bin/utils/export_docs_generators.sh || exit
    
    (For Windows users, please run the script in WSL)
    Commit all changed files.
    This is important, as CI jobs will verify all generator outputs of your HEAD commit as it would merge with master.
    These must match the expectations made by your contribution.
    You may regenerate an individual generator by passing the relevant config(s) as an argument to the script, for example ./bin/generate-samples.sh bin/configs/java*.
    IMPORTANT: Do NOT purge/delete any folders/files (e.g. tests) when regenerating the samples as manually written tests may be removed.
  • If your PR is targeting a particular programming language, @mention the technical committee members, so they are more likely to review the pull request. - Tagging: @TiFu (2017/07) @taxpon (2017/07) @sebastianhaas (2017/07) @kenisteward (2017/07) @Vrolijkx (2017/09) @macjohnny (2018/01) @topce (2018/10) @akehir (2019/07) @petejohansonxo (2019/11) @amakhrov (2020/02) @davidgamero (2022/03) @mkusaka (2022/04) @joscha (2024/10) @KannaKim (2026/07)

Summary by cubic

Fixes TS2527 “inaccessible unique symbol” errors in generated typescript-axios clients by making createRequestFunction return Promise<R> and casting axios.request. Restores TypeScript compatibility with axios 1.19+.

  • Bug Fixes
    • Return Promise<R> from createRequestFunction and cast axios.request as Promise<R>.
    • Update common.mustache and regenerate 15 typescript-axios common.ts samples.
    • Regenerate Python legacy client sample with more robust content-type matching (handles parameters and +json/+yaml).

Written for commit 48a3901. Summary will update on new commits.

Review in cubic

Picazsoo and others added 2 commits July 30, 2026 10:06
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>

@macjohnny macjohnny left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thanks for the fix

@Picazsoo

Copy link
Copy Markdown
Contributor Author

thanks for the fix

No problem. It popped up for me in my unrelated branch as a failure. But I am not a typescript-axios user, so someone better take an honest look if this fix is proper.

@Picazsoo
Picazsoo marked this pull request as ready for review July 30, 2026 08:36

@cubic-dev-ai cubic-dev-ai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No issues found across 16 files

Re-trigger cubic

@macjohnny

Copy link
Copy Markdown
Member

from https://axios.rest/pages/advanced/api-reference#request it seems that Promise<R> is the correct return type

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[BUG] [typescript-axios] axios 1.19.0 support missing

2 participants