Repository navigation
Conversation
…ithout DOM globals Node fetch types declare RequestInit and Response, but not RequestCredentials or WindowOrWorkerGlobalScope. The runtime now takes those shapes from RequestInit so a Node-only project can typecheck the generated client.
Contributor
There was a problem hiding this comment.
All reported issues were addressed across 27 files
Reply with feedback, questions, or to request a fix.
View guided diff | Re-trigger cubic
FetchAPI is now a method type that takes string, URL or Request and an optional init. Middleware can call context.fetch(url) or pass a URL or Request again, and a fetch with a string-only URL or a required init still fits Configuration.fetchApi. None of these names need the DOM lib.
Contributor
There was a problem hiding this comment.
All reported issues were addressed across 27 files (changes from recent commits).
Requires human review: Auto-approval blocked because this review re-detected 1 unresolved issue already reported by Cubic.
View guided diff | Re-trigger cubic
This branch has not been deployed
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.
I changed the typescript-fetch runtime so a Node project can typecheck a generated client without the DOM library.
The runtime named
WindowOrWorkerGlobalScopeandRequestCredentials. Node fetch types do not declare those names. They do declarefetch,RequestInit,Response, andFormData.FetchAPIis now a method type that takesstring | URL | Requestand an optionalRequestInit, so callers and middleware can use it as they didtypeof fetch. Because it is a method type, the middleware wrapper and a user fetch that takes only a string URL or a required init still fit it.URLandRequestare declared by Node fetch types too.FetchCredentialsisNonNullable<RequestInit['credentials']>. With the DOM library loaded, that union matchesRequestCredentials. Node fetch types accept the same indexed access on their own.Changed files:
modules/openapi-generator/src/main/resources/typescript-fetch/runtime.mustachemodules/openapi-generator/src/test/java/org/openapitools/codegen/typescript/fetch/TypeScriptFetchClientCodegenTest.javaruntime.tssamples from the typescript-fetch configs undersamples/client/petstore/typescript-fetchandsamples/client/others/typescript-fetchI regenerated those samples with
./bin/generate-samples.sh ./bin/configs/typescript-fetch*.On commit
4ae5151867da84be7cb596d7842b97649aeef20a,TypeScriptFetchClientCodegenTest.testRuntimeUsesPlatformFetchTypesfailed: 1 test, 1 failure. After the fix that test passed: 1 test, 0 failures. The full class then passed: 60 tests, 0 failures, 0 errors, 0 skipped.Before the fix, tsc 6.0.2 with
@types/node24.19.1, target ES2023, module NodeNext, lib ES2023, types node, strict true, and skipLibCheck false reported 6 errors on the generated runtime and exited 2. After the fix, the same check on the generated client exited 0. A Node-only project that consumed declarations emitted with the DOM library also exited 0.tsc --noEmiton the es6-target sample and the with-npm-version sample exited 0.npm testinsamples/client/petstore/typescript-fetch/tests/isolated-declarations(TypeScript 5.9.3) exited 0.Fixes #25244
TypeScript technical committee: @TiFu @taxpon @sebastianhaas @kenisteward @Vrolijkx @macjohnny @topce @akehir @petejohansonxo @amakhrov @davidgamero @mkusaka @joscha @KannaKim
PR checklist
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.