Skip to content

Support TypeScript 6.0 (completes #2711)#2819

Closed
LMBernardo wants to merge 2 commits into
openapi-ts:mainfrom
LMBernardo:support-typescript-6
Closed

Support TypeScript 6.0 (completes #2711)#2819
LMBernardo wants to merge 2 commits into
openapi-ts:mainfrom
LMBernardo:support-typescript-6

Conversation

@LMBernardo
Copy link
Copy Markdown

@LMBernardo LMBernardo commented May 26, 2026

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 typescript to 6.0.3 and widens the openapi-typescript peer range to ^5.x || ^6.0.0, but its lint check fails, so it can't merge. This branch contains that same bump plus the three minimal changes needed to make lint green. All other checks (test-*, size-limit, CodeQL) already pass on #2711.

The lint task runs tsc, and the first failure is a compiler options error that aborts type-checking before it starts — so each fix uncovers the next. Under typescript@6.0.3:

  1. packages/openapi-fetch/tsconfig.json — remove downlevelIteration. tsc raises TS5101. Per the TS 6.0 release notes: "using --downlevelIteration false with --target es2015 did not error in TypeScript 5.9 and earlier, even though it had no effect. In TypeScript 6.0, setting --downlevelIteration at all will lead to a deprecation error." The option only affects ES5 emit; this package targets ESNext, so it was inert. It was introduced in the package's first commit (Add openapi-fetch #1098) alongside target: ESNext and never had any effect.

  2. packages/openapi-fetch/test/helpers.ts — use Headers.forEach instead of Headers.entries(). With (1) fixed, tsc raises TS2578 (unused @ts-expect-error). That directive — commented FIXME: missing "lib" — suppressed a real error under TS 5.x, whose DOM lib doesn't type Headers.entries() (confirmed: removing it under typescript@5.9.3 yields TS2339). 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 to Headers.forEach, which is typed in both DOM libs, so the helper type-checks under TS 5.x and 6.x with no suppression. (CONTRIBUTING.md rightly values intentional @ts-expect-error error-tests — this one wasn't testing an error, it was a lib-gap workaround.)

  3. packages/openapi-fetch/test/no-strict-null-checks/tsconfig.json — pin rootDir. With (1)–(2) fixed, tsc raises TS6059 (file outside rootDir). Per the TS 6.0 release notes: "Previously, if you did not specify a rootDir, it was inferred based on the common directory of all non-declaration input files. In TypeScript 6.0, the default rootDir will always be the directory containing the tsconfig.json file." 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' ts5to6 codemod performs.

A patch changeset is included so the widened peer range actually publishes. I chose patch to match how dependency/compatibility changes have been versioned here (e.g. @redocly/openapi-core bumps) — happy to make it minor if 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 (node 24, pnpm@10.30.3):

To confirm the changes are TS6-specific and behavior-neutral:

  • TS6-specific: on identical code, tsc@5.9.3 is clean while tsc@6.0.3 reports all three errors.
  • downlevelIteration is emit-neutral: tsc@6.0.3 produces byte-identical output at target: ESNext with the flag absent / false / true.
  • Headers.forEach is behavior-equivalent (same key/value pairs) and type-checks under both tsc@5.9.3 and tsc@6.0.3.

Checklist

  • Unit tests updated — no new tests needed; the change is type-level and the existing 451 tests pass unchanged
  • docs/ updated (if necessary) — not necessary; no user-facing API/behavior change
  • pnpm run update:examples run — N/A; no openapi-typescript generator changes

renovate Bot and others added 2 commits May 12, 2026 11:52
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>
@netlify
Copy link
Copy Markdown

netlify Bot commented May 26, 2026

👷 Deploy request for openapi-ts pending review.

Visit the deploys page to approve it

Name Link
🔨 Latest commit 6687f75

@changeset-bot
Copy link
Copy Markdown

changeset-bot Bot commented May 26, 2026

🦋 Changeset detected

Latest commit: 6687f75

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
openapi-typescript Patch

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

@LMBernardo LMBernardo marked this pull request as ready for review May 26, 2026 19:14
@LMBernardo LMBernardo requested a review from a team as a code owner May 26, 2026 19:14
@LMBernardo LMBernardo requested a review from duncanbeevers May 26, 2026 19:14
@LMBernardo
Copy link
Copy Markdown
Author

Just saw #2774 - moving this back to draft for now. Will close if that one lands.

@LMBernardo LMBernardo marked this pull request as draft May 26, 2026 19:32
@LMBernardo
Copy link
Copy Markdown
Author

After reviewing 2774 - it looks to be a strict superset of my changes here (except for the forEach change, 2774 uses a cast instead). Closing in preference of the pre-existing PR.

@LMBernardo LMBernardo closed this May 26, 2026
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.

Add support for TypeScript 6 Not TS 6 compliant

1 participant