Skip to content

Is Inversify compatible with a pure JavaScript project? #1533

Answered by rsaz
talkohavy asked this question in Q&A
Discussion options

You must be logged in to vote

Hey @talkohavy ,

Yes, any TypeScript package, including Inversify, can indeed run in JavaScript. While TypeScript offers additional capabilities that JavaScript lacks (like decorators), Inversify has you covered!

The Inversify team anticipated this need, so they included a helper function called decorate that makes it easy to apply decorators in JavaScript.

Here’s a simple example to get you started:

main.js

import "reflect-metadata";

import { Container, injectable, decorate } from "inversify";

class Warrior {
    fight() {
        return "Warrior fighting";
    }
}

// Manually decorate the Warrior class as injectable
decorate(injectable(), Warrior);

const container = new Container();
c…

Replies: 1 comment

Comment options

You must be logged in to vote
0 replies
Answer selected by rsaz
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
2 participants