You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Type Error: Cannot read properties of undefined (reading 'Latest')
at isValidIdentifier (\node_modules\tsutils\util\util.js:610:68)
at \node_modules@openapi-codegen\typescript\lib\core\schemaToTypeAliasDeclaration.js:153:126
at Array.map ()
at getType (\node_modules@openapi-codegen\typescript\lib\core\schemaToTypeAliasDeclaration.js:149:69)
at schemaToTypeAliasDeclaration (\node_modules@openapi-codegen\typescript\lib\core\schemaToTypeAliasDeclaration.js:25:220)
at \node_modules@openapi-codegen\typescript\lib\generators\generateSchemaTypes.js:39:76
at Array.reduce ()
at handleTypeAlias (\node_modules@openapi-codegen\typescript\lib\generators\generateSchemaTypes.js:37:84)
at generateTypeAliasDeclarations (\node_modules@openapi-codegen\typescript\lib\generators\generateSchemaTypes.js:58:20)
at generateSchemaTypes (\node_modules@openapi-codegen\typescript\lib\generators\generateSchemaTypes.js:78:25)
We have conducted a thorough investigation into the TypeScript 7 migration path and explored the solution in draft PR #355 (feat/typescript-7-upgrade).
1. Root Cause Analysis
The error originally reported when running with TypeScript 7:
TypeError: Cannot read properties of undefined (reading 'Latest')
at isValidIdentifier (\node_modules\tsutils\util\util.js:610:68)
occurs because:
Generator plugins relied on tsutils, which calls ts.ScriptTarget.Latest on the root typescript import.
In TypeScript 7.x (7.0.2 and 7.1.0-beta), Microsoft redesigned the package structure as part of the Go-based compiler rewrite (tracked upstream in microsoft/TypeScript#63703). The root entry point import ts from "typescript" only exports ./lib/version.cjs ({ version: "7.x" }). The entire compiler API namespace (ts.ScriptTarget, ts.SyntaxKind, ts.factory, ts.createPrinter, etc.) was removed from the package root.
2. Key Findings from typescript@7.1.0-beta
Testing against the latest typescript@7.1.0-beta reveals the new modular package architecture:
Modular Subpaths: AST utilities are now partitioned into distinct subpaths (typescript/ast, typescript/ast/factory, typescript/ast/is).
Factory Changes: Factory functions (createIdentifier, createCallExpression, etc.) are individual functions rather than methods on a unified ts.factory object. Functions have stricter signatures (e.g., createTypeAliasDeclaration requires an Identifier node rather than accepting raw strings).
Renamed Methods: e.g., createPropertySignature is renamed to createPropertySignatureDeclaration.
Tokens: createModifier(kind) was removed in favor of createToken(kind).
Native Emitter / Printer: TypeScript 7.1 delegates AST emitting to a native binary via an IPC RPC channel (typescript/sync). We verified that new sync.API().printer.printNode(...) is functional.
3. Proposed Solution: The Backwards-Compatibility Adapter
To prevent breaking existing custom generators or requiring a high-risk immediate rewrite of all 33 files that interact with the TypeScript compiler, we are using an Adapter Pattern:
Bridge createPrinter with new sync.API().printer and comment/JSDoc injection.
Adapt transformer APIs in cli/src/core/updateConfig.ts & InitCommand.ts.
Achieve green pnpm check:types and pnpm test --run (28/28 test suites, 243/243 tests pass, CI green).
Phase 2: Direct TS 7 Native Style 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:
Activity
el-j commentedon Oct 26, 2026
TypeScript 7 Migration Findings, Compatibility Adapter & Roadmap
We have conducted a thorough investigation into the TypeScript 7 migration path and explored the solution in draft PR #355 (
feat/typescript-7-upgrade).1. Root Cause Analysis
The error originally reported when running with TypeScript 7:
occurs because:
tsutils, which callsts.ScriptTarget.Lateston the roottypescriptimport.7.0.2and7.1.0-beta), Microsoft redesigned the package structure as part of the Go-based compiler rewrite (tracked upstream in microsoft/TypeScript#63703). The root entry pointimport ts from "typescript"only exports./lib/version.cjs({ version: "7.x" }). The entire compiler API namespace (ts.ScriptTarget,ts.SyntaxKind,ts.factory,ts.createPrinter, etc.) was removed from the package root.2. Key Findings from
typescript@7.1.0-betaTesting against the latest
typescript@7.1.0-betareveals the new modular package architecture:typescript/ast,typescript/ast/factory,typescript/ast/is).createIdentifier,createCallExpression, etc.) are individual functions rather than methods on a unifiedts.factoryobject. Functions have stricter signatures (e.g.,createTypeAliasDeclarationrequires anIdentifiernode rather than accepting raw strings).createPropertySignatureis renamed tocreatePropertySignatureDeclaration.createModifier(kind)was removed in favor ofcreateToken(kind).typescript/sync). We verified thatnew sync.API().printer.printNode(...)is functional.3. Proposed Solution: The Backwards-Compatibility Adapter
To prevent breaking existing custom generators or requiring a high-risk immediate rewrite of all 33 files that interact with the TypeScript compiler, we are using an Adapter Pattern:
Why this is the best path:
tsfrom openapi-codegen will retain backwards compatibility.tsutilsentirely and replaces it with an internalisValidIdentifierhelper.4. Two-Phase Roadmap
Phase 1: Compatibility Adapter Layer & Green CI (Completed in PR WIP: TypeScript 7 / 7.1 migration #355)
typescript@7.1.0-beta.tsutilswith internalisValidIdentifier.plugins/typescript/src/typescript.ts(re-export AST nodes, SyntaxKind, enums, factory bridge).createPrinterwithnew sync.API().printerand comment/JSDoc injection.cli/src/core/updateConfig.ts&InitCommand.ts.pnpm check:typesandpnpm test --run(28/28 test suites, 243/243 tests pass, CI green).Phase 2: Direct TS 7 Native Style 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 directtypescript/ast/*imports:Generators (3 files)
plugins/typescript/src/generators/generateFetchers.tsplugins/typescript/src/generators/generateReactQueryComponents.tsplugins/typescript/src/generators/generateSchemaTypes.tsCore AST Declaration Builders (12 files)
plugins/typescript/src/core/createNamedImport.tsplugins/typescript/src/core/createNamespaceImport.tsplugins/typescript/src/core/createOperationFetcherFnNodes.tsplugins/typescript/src/core/createOperationQueryFnNodes.tsplugins/typescript/src/core/createWatermark.tsplugins/typescript/src/core/getDataResponseType.tsplugins/typescript/src/core/getErrorResponseType.tsplugins/typescript/src/core/getOperationTypes.tsplugins/typescript/src/core/getRequestBodyType.tsplugins/typescript/src/core/getVariablesType.tsplugins/typescript/src/core/schemaToEnumDeclaration.tsplugins/typescript/src/core/schemaToTypeAliasDeclaration.tsCore AST Utilities & Scanners (3 files)
plugins/typescript/src/core/analyzeImportUsage.tsplugins/typescript/src/core/getUsedImports.tsplugins/typescript/src/utils/isValidIdentifier.tsCLI AST Transformers & Utilities (6 files)
cli/src/commands/InitCommand.tscli/src/core/generateConfigProperty.tscli/src/core/generateConfigProperty.test.tscli/src/core/updateConfig.tscli/src/core/updateConfig.test.tscli/src/utils/getText.tsPlugin Test Suites & Test Helpers (8 files)
plugins/typescript/src/core/analyzeImportUsage.test.tsplugins/typescript/src/core/createNamedImport.test.tsplugins/typescript/src/core/getOperationTypes.test.tsplugins/typescript/src/core/getUsedImports.test.tsplugins/typescript/src/core/getVariablesType.test.tsplugins/typescript/src/core/schemaToEnumDeclaration.test.tsplugins/typescript/src/core/schemaToTypeAliasDeclaration.test.tsplugins/typescript/src/testUtils.tsAdapter Deprecation & Sunset (1 file)
plugins/typescript/src/typescript.ts(deprecate and sunset once all modules importtypescript/ast/*directly)Related PRs & Issues
fix: drop tsutils (fabien0102#361)