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
If you inject two classes with the same name, the first class in the providers list will be injected for both classes. This is a pretty rare issue, but many third-party packages export classes with generic names such as "Client".
A couple workarounds:
Restructure your dependency tree so that you don't have both classes present in the same module (this may not be practical depending on your code)
Extend the third-party class using a less generic name and use that throughout your code (this could lead to some bugs if you're not careful to always use your wrapper):
import{ClientasFooClient}from'foo';import{ClientasBarClient}from'bar';exportclassMyService{constructor(privatefoo: FooClient,// this will be an instance of FooClientprivatebar: BarClient,// this will also be an instance of FooClient){}}
Expected behavior
The correct class should be injected
Possible Solution
I suspect that somewhere along the line, the class name is being converted to a string. I'm not sure if this is in Nest.js code or the Typescript metadata. If it's in Nest.js code, hopefully it could be fixed by using a symbol or a more unique string. If it's due to the Typescript metadata, I'm not sure if this is solvable in Nest.
Environment
Nest version: 7.0.0
The text was updated successfully, but these errors were encountered:
@jmcdo29 I believe that you are correct, it does appear to be a duplicate. I tried searching before opening the bug, but I guess that I didn't search hard enough.
Bug Report
Current behavior
If you inject two classes with the same name, the first class in the providers list will be injected for both classes. This is a pretty rare issue, but many third-party packages export classes with generic names such as "Client".
A couple workarounds:
Input Code
Here is a reproduction of this bug: https://github.com/stevenhair/congenial-palm-tree
Imagine that you have the module:
and a service:
Expected behavior
The correct class should be injected
Possible Solution
I suspect that somewhere along the line, the class name is being converted to a string. I'm not sure if this is in Nest.js code or the Typescript metadata. If it's in Nest.js code, hopefully it could be fixed by using a symbol or a more unique string. If it's due to the Typescript metadata, I'm not sure if this is solvable in Nest.
Environment
The text was updated successfully, but these errors were encountered: