Need help on using inversifyjs constructor injection. SyntaxError

Hello guys. I need to use inversifyjs for my game.
I got it working well with cocos 3.3.1
but when i try to use decorator in class constructor, i got error showing : SyntaxError: illegal character U+0040

it seems like the @ in constructor consider as illegal character.
is there any reference to configure the decorator to work in constructor parameter?

here is the example of code that cause the SyntaxError

@injectable()
class Katana {
    public hit() {
        return "cut!";
    }
}

@injectable()
class Shuriken {
    public throw() {
        return "hit!";
    }
}

@injectable()
class Ninja {
    private katana!: Katana;
    private shuriken!: Shuriken;

    constructor(
        @inject(Katana) katana: Katana,
        @inject(Shuriken) shuriken: Shuriken
    ) {
        this.katana = katana;
        this.shuriken = shuriken;
    }

    public fight() { return this.katana.hit(); };
    public sneak() { return this.shuriken.throw(); };

}

and here is the example of workaround and using property injection instead of constructor injection


@injectable()
class Katana {
    public hit() {
        return "cut!";
    }
}

@injectable()
class Shuriken {
    public throw() {
        return "hit!";
    }
}

@injectable()
class Ninja {
    @inject(Katana) private katana!: Katana;
    @inject(Shuriken) private shuriken!: Shuriken;

    constructor(
    ) {

    }

    public fight() { return this.katana.hit(); };
    public sneak() { return this.shuriken.throw(); };

}

please help me to solve this, i really want to use constructor injection.
Thank you guys :smiley:

I can ask engineering for their thoughts.

sure, thank you @slackmoehrle . Looking forward for this :grin:

Sorry, we don’t support inversify because we don’t support emitDecoratorMetadata.

This topic was automatically closed 24 hours after the last reply. New replies are no longer allowed.