Skip to content

feat: add TypeScript 6 support#2774

Open
benjamineckstein wants to merge 2 commits intoopenapi-ts:mainfrom
benjamineckstein:feat/typescript-6-support
Open

feat: add TypeScript 6 support#2774
benjamineckstein wants to merge 2 commits intoopenapi-ts:mainfrom
benjamineckstein:feat/typescript-6-support

Conversation

@benjamineckstein
Copy link
Copy Markdown

@benjamineckstein benjamineckstein commented Apr 15, 2026

Summary

Add full TypeScript 6 support — not just the peer dep range, but also a fix for a TS6 behavioral change that breaks Readable<T> and Writable<T>.

Changes

Peer dep & devDependency (commit 1):

  • packages/openapi-typescript/package.json: widen peer dep ^5.x^5.x || ^6.x
  • packages/openapi-typescript-helpers/package.json: upgrade devDependency 5.9.36.0.2

Fix Readable/Writable types (commit 2):
In TypeScript 6, Date extends object evaluates to true (changed from TS5). This caused Readable<T> and Writable<T> to structurally expand built-in objects like Date into { toString: {}; toDateString: {}; ... } instead of preserving the Date type.

Added a guard clause for Date | RegExp | ((...args: never[]) => unknown) before the T extends object branch in both type utilities, preserving built-in objects. This fix is backward compatible with TS5.

Changeset: patch release for both openapi-typescript and openapi-typescript-helpers

Validation

  • pnpm run build — all 4 packages build successfully
  • pnpm test — all 7 test suites pass
  • pnpm run lint — clean

Context

- Widen peer dep: `^5.x` → `^5.x || ^6.x`
- Upgrade devDependency in openapi-typescript-helpers: 5.9.3 → 6.0.2
- Build, tests, and lint all pass with TS6
- No code changes needed

Closes openapi-ts#2723
@benjamineckstein benjamineckstein requested a review from a team as a code owner April 15, 2026 08:44
@benjamineckstein benjamineckstein requested a review from drwpow April 15, 2026 08:44
@netlify
Copy link
Copy Markdown

netlify bot commented Apr 15, 2026

👷 Deploy request for openapi-ts pending review.

Visit the deploys page to approve it

Name Link
🔨 Latest commit a749a52

@changeset-bot
Copy link
Copy Markdown

changeset-bot bot commented Apr 15, 2026

🦋 Changeset detected

Latest commit: a749a52

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

This PR includes changesets to release 4 packages
Name Type
openapi-typescript Patch
openapi-typescript-helpers Patch
openapi-fetch Patch
openapi-react-query 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

…e/Writable types for TS6

In TypeScript 6, `Date extends object` evaluates to `true` (changed from
TS5). This caused `Readable<T>` and `Writable<T>` to structurally expand
Date, RegExp, and function fields instead of preserving them.

Add a guard clause for built-in objects (Date, RegExp, functions) before
the `T extends object` branch in both type utilities.

Ref: openapi-ts#2723
@benjamineckstein benjamineckstein changed the title feat(openapi-typescript): add TypeScript 6 support feat: add TypeScript 6 support Apr 15, 2026
: T extends object
? { [K in keyof T as NonNullable<T[K]> extends $Write<any> ? never : K]: Readable<T[K]> }
: T;
: T extends Date | RegExp | ((...args: never[]) => unknown)
Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In TypeScript 6, Date extends object now evaluates to true (it was false in TS5). Without this guard, Readable<T> would structurally expand Date fields into { toString: {}; toDateString: {}; ... } instead of preserving the Date type — making any schema containing Date fields incompatible with itself when accessed through FetchResponse.

This guard preserves built-in objects (Date, RegExp, functions) by matching them before the generic T extends object branch. It's backward compatible with TS5 since these types were never matched by T extends object there.

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

1 participant