Open brunocapdevila opened 1 year ago
@brunocapdevila Got any solution ?
Any solution?
FWIW, I had this issue, and fixed with 2 changes:
@injectable()
in addition to being registered explicitly with container.register<myInterface>(token, { useClass: myClass })
, and"emitDecoratorMetadata": true
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 @inject('someThingForName') name: string
etc for each of your parameters.
If you don't want to have the params be injected, you can instead use container.register('TotoClass', {useValue: new Toto(... inject yourself)})
or container.register('TotoClassType', {useValue: Toto})
Terrible decision migrate the company api to use that DI library :\
I am also experiencing the same issue.
When using tsx, this problem occurs: Example: "exec": "eslint && tsx watch --tsconfig ./tsconfig.json ./src/index.ts"
However, when running with node/esm, it works without any issues. Example: "exec": "eslint && pnpify node --import './loader.mjs' ./src/index.ts"
I am currently investigating the root cause.
I am also experiencing the same issue.
When using tsx, this problem occurs: Example: "exec": "eslint && tsx watch --tsconfig ./tsconfig.json ./src/index.ts"
However, when running with node/esm, it works without any issues. Example: "exec": "eslint && pnpify node --import './loader.mjs' ./src/index.ts"
I am currently investigating the root cause.
Any luck?
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"