2

I am using TypeScript and creating an API using nestjs and typeorm. Some of the modules in the project are made reusable by extracting them into its own node module. This is causing the Repository type in the external module to not be the same type as the Repository type inside the original package. So when using the external module I get the error

Argument of type 'import("/Users/user/project/node_modules/typeorm/repository/Repository")
.Repository<import("/Users/project/src/user/user.entity").User>' 
is not assignable to parameter of type 
'import("/Users/user/my-module/node_modules/typeorm/repository/Repository")
.Repository<import("/Users/project/src/user/user.entity").User>'.

The typeorm package is listed as a peerDependency in the node package so it should always be the same.

1 Answer 1

2

Your external library seems to have its own type definitions. In this thread, it is suggested to map imports to a folder under node_modules manually in your package.json:

"paths": {
  "typeorm": ["node_modules/typeorm"],
  "typeorm/*": ["node_modules/typeorm/*"]
}

This might only be an issue when using npm link.

Sign up to request clarification or add additional context in comments.

3 Comments

Ops, that was actually a typo from me... the Repository is imported from different paths but not the User type.
Ah ok. :) Did you install your package from npm or did you use npm link?
I used npm link

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.