Skip to content

fix(typescript-fetch): type FetchError cause without parameter property - #25671

Open
thekhegay wants to merge 2 commits into
OpenAPITools:masterfrom
thekhegay:fix/ts-fetch-error-cause
Open

thekhegay wants to merge 2 commits into
OpenAPITools:masterfrom
thekhegay:fix/ts-fetch-error-cause

Conversation

@thekhegay

@thekhegay thekhegay commented Nov 14, 2026 •

Copy link
Copy Markdown
Contributor

With lib es2022 Error already has cause, so parameter property constructor(public cause: Error, ...) in FetchError gives TS4115 under noImplicitOverride. Adding override is not an option, it failes with lib below es2022 (TS4113)

Now cause is assigned in constructor and typed through interface merged with the class. declare cause: Error in class body also compiles, but Babel 7 rejects declare fields unless allowDeclareFields is on, so went with interface (same name is needed for merging, this is the question from #24575). Only FetchError is changed, other parameter properties left as they are

Checked generated runtime.ts with tsc 5.0, 5.9 and 6.0, --strict --noImplicitOverride, lib es2022 and es2015: no errors, master has TS4115 on es2022. e.cause is still typed as Error. Added test in TypeScriptFetchClientCodegenTest, typescript tests pass. Regenerated all 93 typescript configs, only 25 typescript-fetch runtime.ts change, same hunk in each

Fixes #14515

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
    
    Commit all changed files.
  • If your PR is targeting a particular programming language, @mention the technical committee members, so they are more likely to review the pull request.

@TiFu @taxpon @sebastianhaas @kenisteward @Vrolijkx @macjohnny @topce @akehir @petejohansonxo @amakhrov @davidgamero @mkusaka @joscha @KannaKim


Summary by cubic

Fixes the TypeScript 4115 compiler error in typescript-fetch's generated FetchError when noImplicitOverride is enabled and the lib is es2022, where Error already declares cause.

Bug Fixes

  • cause is now assigned in the constructor instead of using a parameter property, since override fails with lib es2015 and declare fields are rejected by Babel 7.
  • cause is typed via a declaration-merged interface and stays typed as Error; verified with tsc 5.0, 5.9, and 6.0 under --strict --noImplicitOverride with es2015 and es2022 libs, and all 25 typescript-fetch samples were regenerated.

Fixes #14515

Written for commit af7087c. Summary will update on new commits.

View guided diff

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

All reported issues were addressed across 27 files

Reply with feedback, questions, or to request a fix.

View guided diff | Re-trigger cubic

This branch has not been deployed

No deployments
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-fetch] Compile error when using "noImplicitOverride" in tsconfig and ES2022

1 participant