InversifyJS icon indicating copy to clipboard operation
InversifyJS copied to clipboard

Error: injectable() accepts too few arguments to be used as a decorator here

Open lamaks opened this issue 3 years ago • 14 comments

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

lamaks avatar Oct 22 '21 22:10 lamaks

This should really not be the case.

Could you maybe try with a fresh install ?

PodaruDragos avatar Oct 25 '21 12:10 PodaruDragos

Did fresh install but still have the issue persisted

Screen Shot 2021-11-01 at 4 08 08 PM

lamaks avatar Nov 01 '21 23:11 lamaks

I am having the exact same problem, same environment

Nciso avatar Nov 02 '21 16:11 Nciso

mm I just updated typescript to ^4.4.4 and it is working

Nciso avatar Nov 02 '21 16:11 Nciso

oh yeah. inversify itself is running on 4,4 since we added support for string | symbol indexable objects. I should have documented that.

PodaruDragos avatar Nov 02 '21 18:11 PodaruDragos

Update to ts 4.4.4 and clean install still did not resolve this. What other changes do we need?

lamaks avatar Nov 03 '21 21:11 lamaks

@PodaruDragos can you please look into this issue?

lamaks avatar Nov 10 '21 21:11 lamaks

@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 ?

PodaruDragos avatar Jan 27 '22 15:01 PodaruDragos

Is there solution for this? I'm getting same error.. :(

WingsDevelopment avatar Mar 31 '22 15:03 WingsDevelopment

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 !

fangkai2017 avatar Apr 07 '22 05:04 fangkai2017

@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 ?

update typescript version to 4.4.4 in package.json file. I had verfied its ok !

fangkai2017 avatar Apr 07 '22 05:04 fangkai2017

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 ...

WingsDevelopment avatar Apr 07 '22 07:04 WingsDevelopment

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 in tsconfig.

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
    }
}

lamaks avatar Apr 14 '22 04:04 lamaks

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

xxidbr9 avatar Apr 17 '22 18:04 xxidbr9