Skip to content

WIP: TypeScript 7 / 7.1 migration - #355

Draft
el-j wants to merge 26 commits into
fabien0102:mainfrom
el-j:feat/typescript-7-upgrade
Draft

el-j wants to merge 26 commits into
fabien0102:mainfrom
el-j:feat/typescript-7-upgrade

Conversation

@el-j

@el-j el-j commented Oct 7, 2026 •

Copy link
Copy Markdown
Contributor

Summary

This pull request prototypes the migration to TypeScript 7 (tested against typescript@7.1.0-beta).

In TypeScript 7, Microsoft fundamentally restructured the typescript package layout and AST compiler APIs as part of the native Go compiler rewrite (tracked in microsoft/TypeScript#63703). Rather than performing a high-risk, all-or-nothing rewrite of all 33 files that interact with TypeScript compiler APIs and breaking backwards compatibility for custom generator plugins, this PR introduces a Backwards-Compatibility Adapter Layer (plugins/typescript/src/typescript.ts) as Phase 1 of our migration roadmap.


Technical Findings: Architectural Changes in TypeScript 7.x

1. Root Export Changes

In TypeScript ≤ 6.x, import ts from "typescript" exported the entire compiler namespace (ts.factory, ts.SyntaxKind, ts.ScriptTarget, ts.createPrinter, etc.).
In TypeScript 7.x (7.0.2 and 7.1.0-beta), the root entry point only exports ./lib/version.cjs ({ version: "7.1.0-beta" }). All compiler symbols were removed from the root package.

2. Subpath Modularization

TypeScript 7.1 exposes specialized subpath modules:

  • typescript/ast: Core AST types, scanners, visitor functions, syntax kinds, and node flags.
  • typescript/ast/factory: Standalone factory functions (e.g., createIdentifier, createCallExpression) rather than methods on a unified ts.factory object.
  • typescript/ast/is: Type guards (e.g., isSourceFile, isImportDeclaration).
  • typescript/sync: Synchronous IPC client (API, Printer) communicating with a native compiler binary.

3. API Signature & Naming Breaking Changes

  • Renamed methods: e.g., createPropertySignature is renamed to createPropertySignatureDeclaration.
  • Modifiers: createModifier(kind) was removed in favor of createToken(kind).
  • Stricter arguments: Declaration functions (e.g., createTypeAliasDeclaration) strictly require AST node objects (such as Identifier) rather than allowing raw string literals.
  • Emitters / Printers: ts.createPrinter() does not exist as a global JavaScript function. Emitting AST nodes is delegated to a native Go binary via an IPC RPC bridge (new sync.API().printer.printNode(node)).
  • Deprecated tools: tsutils is incompatible with TS7 because it accessed ts.ScriptTarget.Latest on the root module.

Architecture: The Backwards-Compatibility Adapter

To safeguard existing ecosystem plugins and allow our internal generators to transition smoothly, we are adopting an adapter-first approach:

┌────────────────────────────────────────────────────────┐
│  Built-in Generators & Third-party Generator Plugins   │
│  (expecting ts.*, ts.factory.*, ts.createPrinter)      │
└───────────────────────────┬────────────────────────────┘
                            │
                            ▼
┌────────────────────────────────────────────────────────┐
│   Compatibility Adapter (plugins/typescript/src/ts.ts) │
│   - Emulates legacy ts namespace & ts.factory methods  │
│   - Wraps & normalizes signatures (tokens, strings)    │
│   - Delegates printing to new sync.API().printer       │
└──────────────┬───────────────────────────┬─────────────┘
               │                           │
               ▼                           ▼
┌──────────────────────────────┐ ┌───────────────────────┐
│ TypeScript 7 Subpaths        │ │ Native IPC Binary     │
│ (ast, ast/factory, ast/is)   │ │ (typescript/sync)     │
└──────────────────────────────┘ └───────────────────────┘

Key Benefits of the Adapter

  1. Zero Downtime for Community Plugins: Third-party custom generators importing the TypeScript helpers continue working without breaking changes.
  2. Safe, Incremental Migration: We get the complete test suite and CI green on TS 7 first, without touching 33+ generator files at once.
  3. Future Modernization Path: In Phase 2, internal generators can gradually migrate to direct typescript/ast/* imports module-by-module.

2-Phase Migration Roadmap

Phase 1: Compatibility Adapter Layer & Green CI (Completed)

  • Clean baseline merged from PR chore: update tooling #353 (all reviewer feedback resolved, CI passing).
  • Upgrade workspace packages to typescript@7.1.0-beta.
  • Replace tsutils with internal isValidIdentifier helper.
  • Verify Prettier and Oxlint run clean under TS 7.1.
  • Complete plugins/typescript/src/typescript.ts adapter:
    • Re-export all AST types, enums (SyntaxKind, EmitHint, NewLineKind, ScriptTarget), and type guards (ts.is*).
    • Implement factory shim mapping old method names (createPropertySignature -> createPropertySignatureDeclaration, createModifier -> createToken).
    • Implement string-to-identifier coercion in declaration factories.
    • Wrap AST printer with new sync.API().printer and full comment/JSDoc injection fidelity.
  • Update CLI AST transformers (updateConfig.ts and InitCommand.ts).
  • Run pnpm check:types and pnpm test --run to 100% green (28/28 test suites, 243/243 tests pass, CI green).

Phase 2: Direct TS 7 Native Modernization (33 Tracked Items)

Once Microsoft finalizes native comment/trivia printing in typescript/sync, the 33 files below can transition from the compatibility adapter to direct typescript/ast/* imports:

1. Generators (3 files)

  • plugins/typescript/src/generators/generateFetchers.ts
  • plugins/typescript/src/generators/generateReactQueryComponents.ts
  • plugins/typescript/src/generators/generateSchemaTypes.ts

2. Core AST Declaration Builders (12 files)

  • plugins/typescript/src/core/createNamedImport.ts
  • plugins/typescript/src/core/createNamespaceImport.ts
  • plugins/typescript/src/core/createOperationFetcherFnNodes.ts
  • plugins/typescript/src/core/createOperationQueryFnNodes.ts
  • plugins/typescript/src/core/createWatermark.ts
  • plugins/typescript/src/core/getDataResponseType.ts
  • plugins/typescript/src/core/getErrorResponseType.ts
  • plugins/typescript/src/core/getOperationTypes.ts
  • plugins/typescript/src/core/getRequestBodyType.ts
  • plugins/typescript/src/core/getVariablesType.ts
  • plugins/typescript/src/core/schemaToEnumDeclaration.ts
  • plugins/typescript/src/core/schemaToTypeAliasDeclaration.ts

3. Core AST Utilities & Scanners (3 files)

  • plugins/typescript/src/core/analyzeImportUsage.ts
  • plugins/typescript/src/core/getUsedImports.ts
  • plugins/typescript/src/utils/isValidIdentifier.ts

4. CLI AST Transformers & Utilities (6 files)

  • cli/src/commands/InitCommand.ts
  • cli/src/core/generateConfigProperty.ts
  • cli/src/core/generateConfigProperty.test.ts
  • cli/src/core/updateConfig.ts
  • cli/src/core/updateConfig.test.ts
  • cli/src/utils/getText.ts

5. Plugin Test Suites & Test Helpers (8 files)

  • plugins/typescript/src/core/analyzeImportUsage.test.ts
  • plugins/typescript/src/core/createNamedImport.test.ts
  • plugins/typescript/src/core/getOperationTypes.test.ts
  • plugins/typescript/src/core/getUsedImports.test.ts
  • plugins/typescript/src/core/getVariablesType.test.ts
  • plugins/typescript/src/core/schemaToEnumDeclaration.test.ts
  • plugins/typescript/src/core/schemaToTypeAliasDeclaration.test.ts
  • plugins/typescript/src/testUtils.ts

6. Adapter Deprecation & Sunset (1 file)

  • plugins/typescript/src/typescript.ts (deprecate and sunset once all modules import typescript/ast/* directly)

Related Issues & PRs

el-j and others added 9 commits October 7, 2026 14:55
- Added allowBuilds for '@swc/core' and 'esbuild' in pnpm-workspace.yaml
- Excluded minimum release age for nock@15.0.1
- Changed moduleResolution from 'Node' to 'Bundler' in tsconfig.json
…sistency

- Updated type definitions in `githubContext.ts`, `githubFetcher.ts`, `githubParameters.ts`, and `githubSchemas.ts` to use single-line union types for better clarity.
- Simplified the `RemoveIndex` type utility in `schemaToTypeAliasDeclaration.ts`.
- Made minor formatting adjustments in `README.md` for consistency.
- Updated `pnpm-workspace.yaml` to use consistent quotation marks.

run check and fix
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Comment thread cli/src/utils/getGithubToken.ts Resolved
@el-j el-j changed the title WIP: TypeScript 7 migration WIP: TypeScript 7 / 7.1 migration Oct 26, 2026
# Conflicts:
#	.oxlintrc.json
#	cli/package.json
#	examples/frontend/package.json
#	package.json
#	plugins/typescript/package.json
#	plugins/typescript/src/typescript.ts
#	pnpm-lock.yaml
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.

Error when migrating to typesrcipt v7

2 participants