fix(typescript-fetch): emit erasable syntax in the runtime template - #24575
Open
mvhenten wants to merge 1 commit into
Open
fix(typescript-fetch): emit erasable syntax in the runtime template#24575mvhenten wants to merge 1 commit into
mvhenten wants to merge 1 commit into
Conversation
Replace constructor parameter properties in runtime.mustache with explicit field declarations and constructor assignments, and declare FetchError.cause through an interface so it needs no override modifier. fixes OpenAPITools#22400 fixes OpenAPITools#14515
macjohnny
reviewed
Aug 3, 2026
|
|
||
| // `cause` is declared through an interface so that it stays compatible with lib targets | ||
| // that already declare `Error.cause` (ES2022+) as well as the ones that do not | ||
| export interface FetchError { |
Member
There was a problem hiding this comment.
why do we need this interface? if we need it, should it have a different name?
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
The
typescript-fetchruntime template uses TypeScript constructor parameter properties in nine places. A parameter property both declares a field and assigns it, so it is not erasable syntax — it cannot be removed by stripping types.Two consequences for generated clients:
runtime.tsat all under type stripping:SyntaxError [ERR_UNSUPPORTED_TYPESCRIPT_SYNTAX]: TypeScript parameter property is not supported in strip-only mode. Since Node 24 this is the default loader for.tsfiles, so a generated client cannot be run without a build step.tsc --erasableSyntaxOnly(TypeScript 5.8+) rejects every one of those sites with TS1294.Separately,
FetchErrordeclarescause, which collides withError.causeon ES2022 and later lib targets. Consumers compiling with--noImplicitOverrideget TS4115. Adding anoverridemodifier is not an option because it breaks the lib targets that predateError.cause(TS4113) — including the generator's own defaultes5/es6output. Declaringcauseon a merged interface instead satisfies both.fixes #22400
fixes #14515
Change
runtime.mustacheonly. Every parameter property becomes an explicit field declaration plus an assignment in the constructor body, andFetchError.causemoves to an interface declaration. Public API, field visibility and emitted JavaScript semantics are unchanged.Verification
Against the regenerated samples:
tsc --noEmitonbuilds/es6-target,builds/with-npm-version,builds/prefix-parameter-interfacesandbuilds/without-runtime-checks— clean.--target es2022 --erasableSyntaxOnly --noImplicitOverride— clean.builds/default/runtime.tsdirectly, constructsConfiguration,BaseAPI,RequiredError,FetchError,ResponseErrorand the fourApiResponseclasses, and reads back their fields. The same script against the previous output fails withSyntaxError: TypeScript parameter property is not supported in strip-only mode.PR checklist
mastercc @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) @dennisameling (2026/02)
Summary by cubic
Emit erasable TypeScript in the
typescript-fetchruntime and fixFetchError.causecompatibility. Generated clients now run with Node 24’s strip-only loader and compile withtsc --erasableSyntaxOnly.FetchError.causeon a merged interface to avoidTS4115/TS4113across lib targets.Written for commit b2bd76d. Summary will update on new commits.