Skip to content
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

"TypeScript's constructor assignments" is not working #1555

Open
mizozobu opened this issue Feb 3, 2024 · 2 comments
Open

"TypeScript's constructor assignments" is not working #1555

mizozobu opened this issue Feb 3, 2024 · 2 comments

Comments

@mizozobu
Copy link

mizozobu commented Feb 3, 2024

"TypeScript's constructor assignments" as stated here is not working.

Expected Behavior

No errors are thrown.

Current Behavior

Throws Error: Missing required @inject or @multiInject annotation in: argument 0 in class Ninja.

Possible Solution

With @inject decorator, everything works perfectly.

Steps to Reproduce (for bugs)

import 'reflect-metadata';
import { Container, injectable } from 'inversify';

@injectable()
class Ninja {

  public constructor(private _dagger:Dagger) {}

  public throwDagger() {
    this._dagger.throw();
  }
}

@injectable()
class Dagger {

  public throw() {
    console.log('throw dagger');
  }
}

const container = new Container();

container.bind<Ninja>(Ninja).toSelf();
container.bind<Dagger>(Dagger).toSelf();

container.get(Ninja).throwDagger();

Context

N/A

Your Environment

  • Version used: 6.0.2
  • Environment name and version (e.g. Chrome 39, node.js 5.4): Node.js 18.19.0
  • Operating System and version (desktop or mobile): macOS 14.2.1
  • Link to your project: N/A

Stack trace

Error: Missing required @inject or @multiInject annotation in: argument 0 in class Ninja.
    at getConstructorArgsAsTarget (/xxx/node_modules/inversify/lib/planning/reflection_utils.js:78:19)
    at getConstructorArgsAsTargets (/xxx/node_modules/inversify/lib/planning/reflection_utils.js:90:22)
    at getTargets (/xxx/node_modules/inversify/lib/planning/reflection_utils.js:56:30)
    at getDependencies (/xxx/node_modules/inversify/lib/planning/reflection_utils.js:41:12)
    at /xxx/node_modules/inversify/lib/planning/planner.js:124:71
    at Array.forEach (<anonymous>)
    at _createSubRequests (/xxx/node_modules/inversify/lib/planning/planner.js:112:20)
    at plan (/xxx/node_modules/inversify/lib/planning/planner.js:154:9)
    at /xxx/node_modules/inversify/lib/container/container.js:626:46
    at Container._get (/xxx/node_modules/inversify/lib/container/container.js:596:38)
@mathysth
Copy link

Hey, I have the same problem did you found an anwser ?

@mizozobu
Copy link
Author

Nope. I'm using @inject instead.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants