openapi-typescript icon indicating copy to clipboard operation
openapi-typescript copied to clipboard

Add support for TypeScript 6

Open jansepke opened this issue 8 months ago • 9 comments

Description

please allow the new TypeScript 6 as a peer dependency for openapi-typescript

Proposal

add version 6 to typescript peer dependency

Extra

jansepke avatar Mar 27 '26 14:03 jansepke

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>.

yamafaktory avatar Mar 30 '26 20:03 yamafaktory

This seems duplicate of #2550

takaram avatar Mar 31 '26 12:03 takaram

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.

benjamineckstein avatar Apr 15 '26 08:04 benjamineckstein

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.

benjamineckstein avatar Apr 15 '26 08:04 benjamineckstein

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.

benjamineckstein avatar Apr 15 '26 08:04 benjamineckstein

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

panwauu avatar Jun 24 '26 07:06 panwauu

Jun 18th Typescript 7.0 RC appeared, so APIs are even more stable! https://devblogs.microsoft.com/typescript/announcing-typescript-7-0-rc/

rvanlaak avatar Jun 26 '26 12:06 rvanlaak

Typescript 7 released

raix avatar Jul 08 '26 20:07 raix

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.

fedorello avatar Nov 04 '26 18:11 fedorello