Search code examples
nestjsbabeljs

Babel_traverse: A type predicate's type must be assignable to its parameter's type


I'm running into the problem mentioned in the title with my Nest.JS project. It appeared after one small commit (nothing special, just updates return types in methods), but when I rolled back all changes it is still remaining. I can't figure out where I have to dig to fix this issue. Also the issue appears only during docker compose build at nest build command. Locally all works perfect: build, debug, start commands work as expected. Full error log:

 node_modules/@types/babel__traverse/index.d.ts:297:72 - error TS2677: A type predicate's type must be assignable to its parameter's type.
15:55:52    Type 'NodePath<T>' is not assignable to type 'NodePath<Node>'.
15:55:52      Types of property 'hasNode' are incompatible.
15:55:52        Type '() => this is NodePath<NonNullable<T>>' is not assignable to type '() => this is NodePath<NonNullable<Node>>'.
15:55:52          Type predicate 'this is NodePath<NonNullable<T>>' is not assignable to 'this is NodePath<NonNullable<Node>>'.
15:55:52            Type 'NodePath<NonNullable<T>>' is not assignable to type 'NodePath<NonNullable<Node>>'.
15:55:52              Types of property 'unshiftContainer' are incompatible.
15:55:52                Type '<Nodes extends Node | readonly Node[]>(listKey: keyof { [P in keyof NonNullable<T> as NonNullable<T>[P] extends any[] ? P : never]: P; }, nodes: Nodes) => NodePaths<...>' is not assignable to type '<Nodes extends Node | readonly Node[]>(listKey: "range" | "leadingComments" | "trailingComments" | "innerComments", nodes: Nodes) => NodePaths<Nodes>'.
15:55:52                  Types of parameters 'listKey' and 'listKey' are incompatible.
15:55:52                    Type 'string' is not assignable to type 'keyof { [P in keyof NonNullable<T> as NonNullable<T>[P] extends any[] ? P : never]: P; }'.
15:55:52                      Type 'string' is not assignable to type 'keyof { [P in keyof NonNullable<T> as NonNullable<T>[P] extends any[] ? P : never]: P; }'.
15:55:52                        Type '"range"' is not assignable to type '(NonNullable<T>[P] extends any[] ? P : never) | (NonNullable<T>["type"] extends any[] ? "type" : never) | (NonNullable<T>["leadingComments"] extends any[] ? "leadingComments" : never) | ... 6 more ... | (NonNullable<...>["extra"] extends any[] ? "extra" : never)'.
15:55:52  
15:55:52  297     findParent<T extends t.Node>(callback: (path: NodePath) => path is NodePath<T>): NodePath<T> | null;
15:55:52                                                                             ~~~~~~~~~~~
15:55:52  node_modules/@types/babel__traverse/index.d.ts:305:66 - error TS2677: A type predicate's type must be assignable to its parameter's type.
15:55:52    Type 'NodePath<T>' is not assignable to type 'NodePath<Node>'.
15:55:52      Types of property 'hasNode' are incompatible.
15:55:52        Type '() => this is NodePath<NonNullable<T>>' is not assignable to type '() => this is NodePath<NonNullable<Node>>'.
15:55:52          Type predicate 'this is NodePath<NonNullable<T>>' is not assignable to 'this is NodePath<NonNullable<Node>>'.
15:55:52            Type 'NodePath<NonNullable<T>>' is not assignable to type 'NodePath<NonNullable<Node>>'.
15:55:52              Types of property 'unshiftContainer' are incompatible.
15:55:52                Type '<Nodes extends Node | readonly Node[]>(listKey: keyof { [P in keyof NonNullable<T> as NonNullable<T>[P] extends any[] ? P : never]: P; }, nodes: Nodes) => NodePaths<...>' is not assignable to type '<Nodes extends Node | readonly Node[]>(listKey: "range" | "leadingComments" | "trailingComments" | "innerComments", nodes: Nodes) => NodePaths<Nodes>'.
15:55:52                  Types of parameters 'listKey' and 'listKey' are incompatible.
15:55:52                    Type 'string' is not assignable to type 'keyof { [P in keyof NonNullable<T> as NonNullable<T>[P] extends any[] ? P : never]: P; }'.
15:55:52                      Type 'string' is not assignable to type 'keyof { [P in keyof NonNullable<T> as NonNullable<T>[P] extends any[] ? P : never]: P; }'.
15:55:52                        Type '"range"' is not assignable to type '(NonNullable<T>[P] extends any[] ? P : never) | (NonNullable<T>["type"] extends any[] ? "type" : never) | (NonNullable<T>["leadingComments"] extends any[] ? "leadingComments" : never) | ... 6 more ... | (NonNullable<...>["extra"] extends any[] ? "extra" : never)'.
15:55:52  
15:55:52  305     find<T extends t.Node>(callback: (path: NodePath) => path is NodePath<T>): NodePath<T> | null;

Solution

  • Using version 7.21.0 on @babel/core devDependency worked just right for me. Mind the version without ^. In case you are using only @babel/traverse try an older version too.