InversifyJS
InversifyJS copied to clipboard
Error: injectable() accepts too few arguments to be used as a decorator here
The new version 6.0.1 has exposing the following error:
'injectable()' accepts too few arguments to be used as a decorator here. Did you mean to call it first and write '@injectable()()'?ts(1329)
Expected Behavior
The decorator should not have the error exposed
Possible Solution
Typescript decorator - accepts too few arguments to be used as a decorator here
Steps to Reproduce (for bugs)
import { injectable } from 'inversify';
@injectable()
export class MyClass {
. . .
}
Your Environment
- Version used: 6.0.1
- Environment name and version (e.g. Chrome 39, node.js 5.4): node.js v12.22.1, tsc v4.3.3
- Operating System and version (desktop or mobile): MacOS 11.6
This should really not be the case.
Could you maybe try with a fresh install ?
Did fresh install but still have the issue persisted

I am having the exact same problem, same environment
mm I just updated typescript to ^4.4.4 and it is working
oh yeah. inversify itself is running on 4,4 since we added support for string | symbol
indexable objects.
I should have documented that.
Update to ts 4.4.4 and clean install still did not resolve this. What other changes do we need?
@PodaruDragos can you please look into this issue?
@lamaks i did look into this, the only thing i can say is that we have no problem in inversify itself.
one thing that can maybe lead to this is not setting the correct target
in tsconfig
.
do you have it set to at lease ES6
?
Is there solution for this? I'm getting same error.. :(
Is there solution for this? I'm getting same error.. :(
update typescript version to 4.4.4 in package.json file. I had verfied its ok !
@lamaks i did look into this, the only thing i can say is that we have no problem in inversify itself. one thing that can maybe lead to this is not setting the correct
target
intsconfig
.do you have it set to at lease
ES6
?
update typescript version to 4.4.4 in package.json file. I had verfied its ok !
My typescript version is 4.6.3.. But yeah I managed to make it work somehow... It actually depends also on framework you are using, I think this error I fixed by changing dependency injection from constructor to property (because I used react, and react have some problems with constructor injections...) Also there might be a problem in your typescript file.. { "compilerOptions": { "target": "ES5", "lib": [ "dom", "dom.iterable", "esnext", "es6" ], "allowJs": true, "skipLibCheck": true, "esModuleInterop": true, "allowSyntheticDefaultImports": true, "strict": true, "forceConsistentCasingInFileNames": true, "noFallthroughCasesInSwitch": true, "module": "esnext", "moduleResolution": "node", "resolveJsonModule": true, "isolatedModules": true, "noEmit": true, "jsx": "react-jsx", "types": ["reflect-metadata"], "experimentalDecorators": true, "emitDecoratorMetadata": true, "strictPropertyInitialization": false, }, "include": [ "src" ] } Also it might be a problem if you don't actually import import 'reflect-metadata'; in every file where you import something from Inversify.js.. Idk whole think seems a little hacky, and I don't really understand why did I have to do all of this stuff and how it will perform, so I decide to not use Inversify.js ...
Maxim Laikine Maxim Laikine FTE i did look into this, the only thing i can say is that we have no problem in inversify itself. one thing that can maybe lead to this is not setting the correct
target
intsconfig
.do you have it set to at lease
ES6
?
The target
is set to ES2019
. Apparently this error manifests on MacOS only but not on Windows.
{
"compilerOptions": {
"target": "ES2019",
"module": "commonjs",
"lib": ["ES2019", "dom", "dom.iterable"],
"moduleResolution": "node",
"emitDecoratorMetadata": true,
"esModuleInterop": true,
"experimentalDecorators": true,
"noImplicitAny": true,
"noUnusedLocals": true,
"noImplicitReturns": true,
"resolveJsonModule": true,
"sourceMap": true,
"declaration": true,
"types": ["reflect-metadata", "@types/jest", "@types/node"]
},
"awesomeTypescriptLoaderOptions": {
"usePrecompiledFiles": true,
"useWebpackText": true
}
}
i found the error,
i got this when im build
../../node_modules/inversify/lib/annotation/injectable.d.ts:1:52 - error TS1005: ',' expected.
1 declare function injectable(): <T extends abstract new (...args: never) => unknown>(target: T) => T;
I take a look at the .d.ts file, and found this
declare function injectable(): <T extends abstract new (...args: never) => unknown>(target: T) => T;
export { injectable };
i try to replace with this
declare function injectable(): (target: any) => any;
export { injectable };
and run perfectly,
so i reverse back to version 5, that error goes away, it all error on the typescript, but the main package are no problem
try update the typescript first, if still got the same error, just reverse back