Skip to content

Support TypeScript5.9.x and hey-api/openapi-ts 0.92.x#192

Open
TakehiroTada wants to merge 8 commits into7nohe:mainfrom
TakehiroTada:feature/support-ts-5.9.x
Open

Support TypeScript5.9.x and hey-api/openapi-ts 0.92.x#192
TakehiroTada wants to merge 8 commits into7nohe:mainfrom
TakehiroTada:feature/support-ts-5.9.x

Conversation

@TakehiroTada
Copy link

Summary

This PR upgrades the core dependencies to support TypeScript 5.9.x and the latest @hey-api/openapi-ts (0.92.3), which introduced a completely new plugins-based configuration system.

Dependency Upgrades

Package Before After
typescript 5.5.4 5.9.3
ts-morph 23.x 27.x
@hey-api/openapi-ts 0.53.8 0.92.3

Key Changes

1. Migration to @hey-api/openapi-ts Plugins System

@hey-api/openapi-ts 0.92.3 replaced its flat configuration (client, schemas, services, types) with a plugins array. The generate.mts has been updated to build the plugins array from CLI options:

  • @hey-api/client-fetch / @hey-api/client-axios — selected via --client
  • @hey-api/typescript — accepts enums option from --enums
  • @hey-api/sdk — accepts operationId option from --noOperationId
  • @hey-api/schemas — conditionally added (controlled by --noSchemas), accepts type from --schemaType

2. Backward-Compatible services.gen.ts Shim

The new @hey-api/openapi-ts generates sdk.gen.ts (SDK functions) and client.gen.ts (client instance) instead of the old services.gen.ts. To avoid breaking existing user code that imports from services.gen.ts, a shim file is auto-generated:

// services.gen.ts (auto-generated shim)
export * from './client.gen';
export * from './sdk.gen';

3. TypeScript 5.9 Compatibility for ts-morph

In TS 5.9, the SyntaxKind enum values shifted (e.g., ArrowFunction changed from 219 to 220). Since ts-morph bundles its own TypeScript internally, using ts.isArrowFunction() from a separately imported typescript package caused mismatches. The fix:

  • service.mts: Updated getMethodsFromService() to handle both old-style (block body) and new-style (expression body) arrow functions generated by @hey-api/sdk
  • Type narrowing: Replaced as type assertions with proper type guards using ts.isArrowFunction(), ts.isBlock(), etc.

4. Codegen Bug Fixes

  • Error type extraction: Fixed createUseQuery.mts and createUseMutation.mts to correctly extract error types from the new SDK function signatures (generics order changed: <ResponseType, ErrorType, ThrowOnError>)
  • Optional parameters: Fixed generated hooks to make clientOptions optional when the SDK function has no required parameters (using Options<Data, true> = {} default)
  • Import paths: Updated createImports.mts to import Options type from the new client module path instead of the old core path

5. skipLibCheck: false Support

  • Added src/vendor-typestubs.d.ts with type stubs for @hey-api/openapi-ts internal modules that lack proper type exports
  • Added a pnpm patch for @hey-api/openapi-ts@0.92.3 to fix a missing type export
  • Added biome.json to exclude vendor type stubs from linting

6. Documentation Updates

  • Updated directory structure in introduction.mdx to reflect new file layout (sdk.gen.ts, client.gen.ts, client/, core/)
  • Marked --useDateType and --debug as deprecated in cli-options.mdx (no equivalent in the new plugins API)
  • Added notes about --format / --lint only affecting the queries/ directory
  • Updated usage.mdx to mention the services.gen.ts backward-compatibility shim

Deprecated CLI Options

The following options are accepted but have no effect:

Option Reason
--useDateType No equivalent in the @hey-api/typescript plugin
--debug No equivalent in the new @hey-api/openapi-ts config

Files Changed (26 files)

Core codegen:

  • src/generate.mts — Plugins-based config, shim generation, CLI option mapping
  • src/service.mts — TS 5.9 compatible AST traversal for new SDK output format
  • src/createUseQuery.mts — Error type extraction, optional params
  • src/createUseMutation.mts — Error type extraction, optional params
  • src/createExports.mts — Type guard refactoring
  • src/createImports.mts — New import paths
  • src/createSource.mts — Updated service file reference
  • src/common.mts — Simplified type utilities
  • src/constants.mts — Updated service file name constant

Tests:

  • tests/__snapshots__/createSource.test.ts.snap — Updated snapshots
  • tests/__snapshots__/generate.test.ts.snap — Updated snapshots
  • tests/createImports.test.ts — Updated test expectations
  • tests/service.test.ts — Updated test expectations

Docs:

  • docs/src/content/docs/guides/introduction.mdx
  • docs/src/content/docs/guides/cli-options.mdx
  • docs/src/content/docs/guides/usage.mdx

Config & types:

  • package.json, pnpm-lock.yaml
  • biome.json, src/vendor-typestubs.d.ts
  • patches/@hey-api__openapi-ts@0.92.3.patch

Test Plan

  • All existing snapshot tests pass (pnpm test)
  • CLI options verified manually with petstore.yaml:
    • --enums javascript / --enums typescript
    • --noOperationId (function names change from operationId-based to HTTP method + path)
    • --noSchemas (schemas.gen.ts not generated)
    • --schemaType form (schemas.gen.ts generated with form type)
    • --useDateType / --debug (deprecated, no error)
  • Example apps updated (nextjs-app, tanstack-router-app)

TakehiroTada and others added 8 commits January 23, 2026 11:43
- Use Identifier.text instead of getText() for robust HTTP method name extraction
- Fix JSDoc extraction by searching from VariableStatement level instead of ArrowFunction
- Update tests/utils.ts to use hey-api 0.90.1 plugins API
- Update test snapshots to include correctly extracted JSDoc comments

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
- service.mts: remove all `as` casts by using ts.isArrowFunction,
  ts.isReturnStatement, ts.isCallExpression type guards for proper narrowing
- createExports.mts: use reduce generic, ts.isTypeLiteralNode,
  ts.isPropertySignature type guards, and type predicate filter
- createUseQuery.mts: add comments explaining unavoidable assertions
  on factory-created nodes

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
- Upgrade @hey-api/openapi-ts from 0.90.1 to 0.92.3
- Add vendor-typestubs.d.ts for framework-specific modules (Angular, Vue, Nuxt, ofetch)
  bundled in @hey-api/openapi-ts but not used in this project
- Add @types/semver for @hey-api/shared's semver import
- Patch @hey-api/openapi-ts to suppress TS2416 toAst() variance error
  caused by bundled declaration file incorrectly constraining base type
- Remove skipLibCheck: true from tsconfig.json (now defaults to false)
- Add biome override to allow any in type stubs file

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
- Generate backward-compatible services.gen.ts shim (re-exports from
  client.gen and sdk.gen) so existing import paths continue to work
- Fix missing error type references: fall back to `unknown` when
  ${methodName}Error type does not exist in generated types
- Fix incorrect `= {}` default for required SDK parameters by checking
  parameter optionality directly instead of extracting type properties
- Add @hey-api/client-fetch to nextjs-app and tanstack-router-app
- Add target: es2017 to nextjs-app tsconfig for iterator support
- Remove stale @hey-api/client-fetch import from react-app App.tsx
- Update test snapshots

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
- Map CLI options (--enums, --noOperationId, --noSchemas, --schemaType)
  to the new @hey-api/openapi-ts plugins API in generate.mts
- Mark --useDateType and --debug as deprecated (no equivalent in new API)
- Update introduction.mdx with new output directory structure
  (sdk.gen.ts, client.gen.ts, client/, core/)
- Update cli-options.mdx with accurate option descriptions
- Update usage.mdx to mention sdk.gen.ts and services.gen.ts shim

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@vercel
Copy link

vercel bot commented Feb 11, 2026

@TakehiroTada is attempting to deploy a commit to the Daiki Urata's projects Team on Vercel.

A member of the Team first needs to authorize it.

@7nohe 7nohe self-requested a review February 12, 2026 00:11
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.

1 participant