Skip to content

Multiple local symlinks wrongly leading to TS2345 #6365

@ahom

Description

@ahom

Error

While compiling a project that depends on local packages (symlinked from node_modules folder) I'm getting the following error even though both types are exactly the same.

src/app.tsx(21,65): error TS2345: Argument of type 'SqlPipeline' is not assignable to parameter of type 'Pass<string, Node>'.
  Types of property 'transform' are incompatible.
    Type '(input: string) => Node' is not assignable to type '(input: string) => Node'.
      Type 'Node' is not assignable to type 'Node'.
        Property '_children' is protected but type 'Node' is not a class derived from 'Node'.

Symlinks setup

Here I'm trying to compile the debug/sql_to_mongo project

core/

frontend/sql/node_modules/llqm-core -> ../../../core

backend/mongo/node_modules/llqm-core -> ../../../core

debug/sql_to_mongo/node_modules/llqm-core -> ../../../core
debug/sql_to_mongo/node_modules/llqm-frontend-sql-> ../../../frontend/sql
debug/sql_to_mongo/node_modules/llqm-backend-mongo -> ../../../backend/mongo

The problem seems to be happening because when resolving the llqm-core module from debug/sql_to_mongo, frontend/sql and backend/mongo they each point, from Typescript's perspective, to different folders, but they really all resolve to the same one.

Compiling with --listFiles to show the dependencies being resolved

src/app.tsx(21,65): error TS2345: Argument of type 'SqlPipeline' is not assignable to parameter of type 'Pass<string, Node>'.
  Types of property 'transform' are incompatible.
    Type '(input: string) => Node' is not assignable to type '(input: string) => Node'.
      Type 'Node' is not assignable to type 'Node'.
        Property '_children' is protected but type 'Node' is not a class derived from 'Node'.
/home/ahom/projects/llqm/packages/debug/sql_to_mongo/node_modules/typescript/lib/lib.d.ts
node_modules/llqm-core/src/pass.ts
node_modules/llqm-core/src/pipeline.ts
node_modules/llqm-core/src/ir/node.ts
node_modules/llqm-core/src/compiler.ts
node_modules/llqm-core/src/schema.ts
node_modules/llqm-core/src/ir/operation.ts
node_modules/llqm-core/src/ir/query.ts
node_modules/llqm-core/src/ir/index.ts
node_modules/llqm-core/index.ts
node_modules/llqm-frontend-sql/node_modules/llqm-core/src/pass.ts
node_modules/llqm-frontend-sql/node_modules/llqm-core/src/pipeline.ts
node_modules/llqm-frontend-sql/node_modules/llqm-core/src/ir/node.ts
node_modules/llqm-frontend-sql/node_modules/llqm-core/src/compiler.ts
node_modules/llqm-frontend-sql/node_modules/llqm-core/src/schema.ts
node_modules/llqm-frontend-sql/node_modules/llqm-core/src/ir/operation.ts
node_modules/llqm-frontend-sql/node_modules/llqm-core/src/ir/query.ts
node_modules/llqm-frontend-sql/node_modules/llqm-core/src/ir/index.ts
node_modules/llqm-frontend-sql/node_modules/llqm-core/index.ts
node_modules/llqm-frontend-sql/src/ast.ts
node_modules/llqm-frontend-sql/src/loc.ts
node_modules/llqm-frontend-sql/src/lexer.ts
node_modules/llqm-frontend-sql/src/lexer_pass.ts
node_modules/llqm-frontend-sql/src/remove_tokens_pass.ts
node_modules/llqm-frontend-sql/src/parser.ts
node_modules/llqm-frontend-sql/src/parser_pass.ts
node_modules/llqm-frontend-sql/src/gencode_pass.ts
node_modules/llqm-frontend-sql/src/pipeline.ts
node_modules/llqm-frontend-sql/src/mode.ts
node_modules/llqm-frontend-sql/index.ts
node_modules/llqm-backend-mongo/node_modules/llqm-core/src/pass.ts
node_modules/llqm-backend-mongo/node_modules/llqm-core/src/pipeline.ts
node_modules/llqm-backend-mongo/node_modules/llqm-core/src/ir/node.ts
node_modules/llqm-backend-mongo/node_modules/llqm-core/src/compiler.ts
node_modules/llqm-backend-mongo/node_modules/llqm-core/src/schema.ts
node_modules/llqm-backend-mongo/node_modules/llqm-core/src/ir/operation.ts
node_modules/llqm-backend-mongo/node_modules/llqm-core/src/ir/query.ts
node_modules/llqm-backend-mongo/node_modules/llqm-core/src/ir/index.ts
node_modules/llqm-backend-mongo/node_modules/llqm-core/index.ts
node_modules/llqm-backend-mongo/src/gencode_pass.ts
node_modules/llqm-backend-mongo/index.ts
src/editor.tsx
typings/react/react.d.ts
src/react-object-inspector.d.ts
src/compile_log.tsx
src/utils.ts
src/app.tsx
src/boot.tsx
typings/codemirror/codemirror.d.ts
typings/react-bootstrap/react-bootstrap.d.ts
typings/react/react-dom.d.ts
typings/tsd.d.ts

Hacky fix

By modifying the resolution of external modules to follow symlinks (with fs.realpath) it is now compiling properly.

  • Would it be ok to provide a PR for that?
  • Would you know a good place where this should be called?

Right now I:

  • added a fs.realpath call to ts.sys.resolvePath (for node)
  • and called it from ts.resolveModuleNameonly when it is an external import

I'm not too sure if this is the right way to go.

--listFiles after fix

/home/ahom/projects/llqm/packages/debug/sql_to_mongo/node_modules/typescript/lib/lib.d.ts
/home/ahom/projects/llqm/packages/core/src/pass.ts
/home/ahom/projects/llqm/packages/core/src/pipeline.ts
/home/ahom/projects/llqm/packages/core/src/ir/node.ts
/home/ahom/projects/llqm/packages/core/src/compiler.ts
/home/ahom/projects/llqm/packages/core/src/schema.ts
/home/ahom/projects/llqm/packages/core/src/ir/operation.ts
/home/ahom/projects/llqm/packages/core/src/ir/query.ts
/home/ahom/projects/llqm/packages/core/src/ir/index.ts
/home/ahom/projects/llqm/packages/core/index.ts
/home/ahom/projects/llqm/packages/frontend/sql/src/ast.ts
/home/ahom/projects/llqm/packages/frontend/sql/src/loc.ts
/home/ahom/projects/llqm/packages/frontend/sql/src/lexer.ts
/home/ahom/projects/llqm/packages/frontend/sql/src/lexer_pass.ts
/home/ahom/projects/llqm/packages/frontend/sql/src/remove_tokens_pass.ts
/home/ahom/projects/llqm/packages/frontend/sql/src/parser.ts
/home/ahom/projects/llqm/packages/frontend/sql/src/parser_pass.ts
/home/ahom/projects/llqm/packages/frontend/sql/src/gencode_pass.ts
/home/ahom/projects/llqm/packages/frontend/sql/src/pipeline.ts
/home/ahom/projects/llqm/packages/frontend/sql/src/mode.ts
/home/ahom/projects/llqm/packages/frontend/sql/index.ts
/home/ahom/projects/llqm/packages/backend/mongo/src/gencode_pass.ts
/home/ahom/projects/llqm/packages/backend/mongo/index.ts
src/editor.tsx
typings/react/react.d.ts
src/react-object-inspector.d.ts
src/compile_log.tsx
src/utils.ts
src/app.tsx
src/boot.tsx
typings/codemirror/codemirror.d.ts
typings/react-bootstrap/react-bootstrap.d.ts
typings/react/react-dom.d.ts
typings/tsd.d.ts

Thanks!

Metadata

Metadata

Assignees

No one assigned

    Labels

    BugA bug in TypeScriptFixedA PR has been merged for this issue

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions