Add support for TypeScript 6
Description
please allow the new TypeScript 6 as a peer dependency for openapi-typescript
Proposal
add version 6 to typescript peer dependency
Extra
- [ ] I’m willing to open a PR (see CONTRIBUTING.md)
Hi :),
I'm working on a company project where we've recently switched to TypeScript 6.
One issue we faced is the openapi-typescript-helpers package (0.1.0). In TypeScript 6, Date extends object evaluates to true, which was not the case in TypeScript 5. This causes Readable<T> to structurally expand Date fields into { toString: {}; toDateString: {}; ... } instead of preserving Date, making any schema type containing Date fields incompatible with itself when accessed through FetchResponse.
Currently the package provides:
type Readable<T> = T extends $Write<any> ? never
: T extends $Read<infer U> ? Readable<U>
: T extends (infer E)[] ? Readable<E>[]
: T extends object ? { [K in keyof T as NonNullable<T[K]> extends $Write<any> ? never : K]: Readable<T[K]>; }
: T;
What would be needed would be something in that vein:
type Readable<T> = T extends $Write<any> ? never
: T extends $Read<infer U> ? Readable<U>
: T extends (infer E)[] ? Readable<E>[]
: T extends Date | RegExp | ((...args: never[]) => unknown) ? T // preserve built-in objects
: T extends object ? { [K in keyof T as NonNullable<T[K]> extends $Write<any> ? never : K]: Readable<T[K]>; }
: T;
And then we have the same issue with Writable<T>.
This seems duplicate of #2550
PR #2773 widens the peer dependency to ^5.x || ^6.x — verified that build, tests, and lint all pass with no code changes needed.
This is a minimal, focused fix (just the peer dep range + changeset) compared to #2711 which also upgrades the monorepo's own TypeScript devDependency to v6.
Updated PR: #2774 — adds full TypeScript 6 support (peer dep widened to ^5.x || ^6.x, devDependency upgraded to 6.0.2, changeset included). Build, tests, and lint all pass.
PR #2774 now also includes the fix for Readable<T> and Writable<T> reported by @yamafaktory above — added a guard clause for Date | RegExp | functions before the T extends object branch in both types. Backward compatible with TS5.
Please try to accelerate the support for new typescript versions.
In April the team announced typescript 7.0 beta with the comment "Our current plan is to release TypeScript 7.0 within the next two months".
So there will be another major release in the next weeks while the current one is not even supported ty openapi-typescript
Jun 18th Typescript 7.0 RC appeared, so APIs are even more stable! https://devblogs.microsoft.com/typescript/announcing-typescript-7-0-rc/
Since openapi-typescript is now in maintenance mode, this is fixed in openapi-typesafe, a maintained fork of openapi-typescript, openapi-fetch and openapi-react-query: TypeScript 6 is supported (CI tests TypeScript 5.4, 5.9, 6.0, 7.0 and the 7.1 beta). Apart from fixes like this one, the CLI flags, Node API and output match openapi-typescript 7.13, and npx openapi-typesafe-migrate --write moves a project over. https://github.com/openapi-typesafe/openapi-typesafe
The 1.0 release candidate is on npm: npm i -D openapi-typesafe@next.