Support TypeScript 6.0 (completes #2711)#2819
Closed
LMBernardo wants to merge 2 commits into
Closed
Conversation
Resolve three TypeScript 6.0 errors surfaced when the dev dependency is bumped to 6.0.3 (see openapi-ts#2711). All other CI checks already pass on that PR. - Remove the deprecated `downlevelIteration` option, which is a no-op at `target: ESNext` and now raises TS5101. - Replace `Headers.entries()` (typed only in TS 6's DOM lib) with `Headers.forEach` in the test helper, dropping an obsolete `@ts-expect-error` and keeping the helper type-correct under both TS 5.x and 6.x. - Pin `rootDir` in the no-strict-null-checks tsconfig; TS 6.0 changed the default `rootDir` to the tsconfig's own directory. Add a changeset to publish the widened `typescript` peer range. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
👷 Deploy request for openapi-ts pending review.Visit the deploys page to approve it
|
🦋 Changeset detectedLatest commit: 6687f75 The changes in this PR will be included in the next version bump. This PR includes changesets to release 1 package
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
Author
|
Just saw #2774 - moving this back to draft for now. Will close if that one lands. |
Author
|
After reviewing 2774 - it looks to be a strict superset of my changes here (except for the |
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.
Note
This PR was prepared with AI assistance. Flagging that up front for transparency. Every technical claim below is backed by the linked TypeScript 6.0 release notes or has notes on how to reproduce the checks (commands under "How to Review"), and the result is verified locally on the pinned toolchain.
Changes
This makes
openapi-typescript's CI pass under TypeScript 6.0, completing the dependency bump in #2711.#2711 (opened by Renovate) bumps the dev
typescriptto6.0.3and widens theopenapi-typescriptpeer range to^5.x || ^6.0.0, but itslintcheck fails, so it can't merge. This branch contains that same bump plus the three minimal changes needed to makelintgreen. All other checks (test-*,size-limit, CodeQL) already pass on #2711.The
linttask runstsc, and the first failure is a compiler options error that aborts type-checking before it starts — so each fix uncovers the next. Undertypescript@6.0.3:packages/openapi-fetch/tsconfig.json— removedownlevelIteration.tscraisesTS5101. Per the TS 6.0 release notes: "using--downlevelIteration falsewith--target es2015did not error in TypeScript 5.9 and earlier, even though it had no effect. In TypeScript 6.0, setting--downlevelIterationat all will lead to a deprecation error." The option only affects ES5 emit; this package targetsESNext, so it was inert. It was introduced in the package's first commit (Add openapi-fetch #1098) alongsidetarget: ESNextand never had any effect.packages/openapi-fetch/test/helpers.ts— useHeaders.forEachinstead ofHeaders.entries(). With (1) fixed,tscraisesTS2578(unused@ts-expect-error). That directive — commentedFIXME: missing "lib"— suppressed a real error under TS 5.x, whose DOM lib doesn't typeHeaders.entries()(confirmed: removing it undertypescript@5.9.3yieldsTS2339). TS 6.0's DOM lib types it, so the suppression is now unused. Rather than tie the test to one compiler version, this switches toHeaders.forEach, which is typed in both DOM libs, so the helper type-checks under TS 5.x and 6.x with no suppression. (CONTRIBUTING.mdrightly values intentional@ts-expect-errorerror-tests — this one wasn't testing an error, it was a lib-gap workaround.)packages/openapi-fetch/test/no-strict-null-checks/tsconfig.json— pinrootDir. With (1)–(2) fixed,tscraisesTS6059(file outsiderootDir). Per the TS 6.0 release notes: "Previously, if you did not specify arootDir, it was inferred based on the common directory of all non-declaration input files. In TypeScript 6.0, the defaultrootDirwill always be the directory containing thetsconfig.jsonfile." This config imports../helpers.ts, which fell outside the new default. Setting"rootDir": "../.."restores the 5.9-inferred root — the same adjustment the release notes'ts5to6codemod performs.A
patchchangeset is included so the widened peer range actually publishes. I chosepatchto match how dependency/compatibility changes have been versioned here (e.g.@redocly/openapi-corebumps) — happy to make itminorif you'd prefer.I'm opening this as a separate PR because #2711 is Renovate-managed and I can't push to its branch; glad to have these commits applied onto #2711 instead if that's easier for you.
Closes #2723
Closes #2550
How to Review
On the pinned toolchain (
node24,pnpm@10.30.3):pnpm run lint→ all packages pass (the failing task on chore(deps): update dependency typescript to v6 #2711 wasopenapi-fetch#lint).pnpm --filter openapi-fetch test→ 451 tests pass, no type errors.To confirm the changes are TS6-specific and behavior-neutral:
tsc@5.9.3is clean whiletsc@6.0.3reports all three errors.downlevelIterationis emit-neutral:tsc@6.0.3produces byte-identical output attarget: ESNextwith the flag absent /false/true.Headers.forEachis behavior-equivalent (same key/value pairs) and type-checks under bothtsc@5.9.3andtsc@6.0.3.Checklist
docs/updated (if necessary) — not necessary; no user-facing API/behavior changepnpm run update:examplesrun — N/A; noopenapi-typescriptgenerator changes