-
Notifications
You must be signed in to change notification settings - Fork 170
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Basic register throws TypeInfo not known if constructor has parameters #223
Comments
@brunocapdevila Got any solution ? |
Any solution? |
FWIW, I had this issue, and fixed with 2 changes:
|
Given everything I've read about TSyringe, the solution is to inject each of your parameters. This sort of makes sense, given that in order for a class to be injectable, TSyringe needs to know how to fulfill each parameter in the constructor. In this case, you'd have to If you don't want to have the params be injected, you can instead use |
Terrible decision migrate the company api to use that DI library :\ |
I am also experiencing the same issue. When using tsx, this problem occurs: However, when running with node/esm, it works without any issues. I am currently investigating the root cause. |
Any luck? |
Having the same issue running basic example: import "reflect-metadata";
import { container, injectable } from "tsyringe";
@injectable()
class Foo {}
@injectable()
class Bar {
constructor(public myFoo: Foo) {}
}
const myBar = container.resolve(Bar); If class has no constructor parameters, it just works. Anyone can shed some light on it? Thanks a lot! |
Describe the bug
While doing some unit test to evaluate the library I found that a simple class registration throws TypeInfo not Known only when it has construction parameters. It works when no construction parameters.
I must be missing something, but I already added
To Reproduce
const papa = container.resolve(Papa);
--> works becausePapa
class has no parametersconst foo = container.resolve<Toto>(Toto);
-> fails withTypeInfo not know
Toto
class constructor with an empty one -> it worksBy the way, I also tried having
Toto
constructor with onlyBar
parameter and still fails (in case primitive type needed to be handled differently)Expected behavior
The instruction
container.register(Toto, { useClass: Toto });
should be enough to create the relatedTypeInfo
Version:
"tsyringe": "^4.7.0"
The text was updated successfully, but these errors were encountered: