benjamn / ast-types

Esprima-compatible implementation of the Mozilla JS Parser API
MIT License
1.13k stars 195 forks source link

Type errors with TypeScript 5.4+ #948

Open freben opened 4 months ago

freben commented 4 months ago

When upgrading to TypeScript 5.4+, importing from ast-types leads to type errors.

Reproduction:

Result: image

Obeying the instructions and explicitly making them type imports solves the problem:

-import { ASTNode, Type, AnyType, Field } from "./lib/types";
+import { ASTNode, type Type, AnyType, Field } from "./lib/types";
-import { NodePath } from "./lib/node-path";
+import { type NodePath } from "./lib/node-path";
-import { builders } from "./gen/builders";
+import { type builders } from "./gen/builders";
craiganderson-iotv commented 6 days ago

A suitable patch-package for these changes is ast-types+0.14.2.patch:

diff --git a/node_modules/ast-types/main.d.ts b/node_modules/ast-types/main.d.ts
index 6b9a8d0..1010bb5 100644
--- a/node_modules/ast-types/main.d.ts
+++ b/node_modules/ast-types/main.d.ts
@@ -1,7 +1,7 @@
-import { ASTNode, Type, AnyType, Field } from "./lib/types";
-import { NodePath } from "./lib/node-path";
+import { ASTNode, type Type, AnyType, Field } from "./lib/types";
+import { type NodePath } from "./lib/node-path";
 import { namedTypes } from "./gen/namedTypes";
-import { builders } from "./gen/builders";
+import { type builders } from "./gen/builders";
 import { Visitor } from "./gen/visitor";
 declare const astNodesAreEquivalent: {
     (a: any, b: any, problemPath?: any): boolean;

Eventually, it looks like ast-types-x could be a well-maintained replacement.