I am trying to use inversify JS to inject dependencies on TypeScript App. I started by using the example of https://github.com/inversify/InversifyJS page :
// file interfaces.ts
interface Warrior {
fight(): string;
}
// file types.ts
const TYPES = {
Warrior: Symbol("Warrior")
};
export { TYPES };
// file entities.ts
import { injectable, inject } from "inversify";
import "reflect-metadata";
import { Warrior } from "./interfaces"
import { TYPES } from "./types";
@injectable()
class WarriorImpl implements Warrior {
public constructor(){
}
public fight() { return "I fight"; }
}
export { WarriorImpl };
// file inversify.config.ts
import { Container } from "inversify";
import TYPES from "./types";
import { Warrior } from "./interfaces";
import { WarriorImpl } from "./entities";
const myContainer = new Container();
myContainer.bind<Warrior>(TYPES.Warrior).to(WarriorImpl);
export { myContainer };
I applied what is provided in the example but Vscode and tsc
failed at the binding line by showing this error [ts] Untyped function calls may not accept type arguments. [ts] Cannot find name 'Warrior'.
Your example is clean and correct all you have to do is to upgrade your typescript version in your
package.json