inversify / InversifyJS

A powerful and lightweight inversion of control container for JavaScript & Node.js apps powered by TypeScript.
http://inversify.io/
MIT License
11.02k stars 712 forks source link

Decorators cannot be used to decorate parameters #1574

Open mohammadamer opened 4 weeks ago

mohammadamer commented 4 weeks ago

Expected Behavior

I expect to implement unit test and unit tests to pass without errors.

Current Behavior

I got this error "Decorators cannot be used to decorate parameters" when implementing unit testing in my app. I expect that unit tests to pass with pointing to the line where I implement the "@inject" All errors says "Decorators cannot be used to decorate parameters" and pointing to the "@inject" in the constructor of the class.

Possible Solution

by removing the "@inject" from constructor, unit tests pass.

Steps to Reproduce (for bugs)

Got the error with this syntex:

@injectable()
export default class MutationHandler implements IMutationHandler {
    private _observers = new Map<string, MutationObserver>();
    private _sharePointPageHandler: ISharePointPageHandler;
    public constructor(
        @inject(TYPES.ISharePointPageHandler) sharePointPageHandler: ISharePointPageHandler
    ) {
        this._sharePointPageHandler = sharePointPageHandler;
        this.handleActionsSubcellMutation = this.handleActionsSubcellMutation.bind(this);
    }
}

Test passes with this syntex

export default class MutationHandler implements IMutationHandler {
    private _observers = new Map<string, MutationObserver>();
    private _sharePointPageHandler: ISharePointPageHandler;
    public constructor(
        sharePointPageHandler: ISharePointPageHandler
    ) {
        this._sharePointPageHandler = sharePointPageHandler;
        this.handleActionsSubcellMutation = this.handleActionsSubcellMutation.bind(this);
    }

Context

It prevent us from building unit tests for the project.

Your Environment

Another Environment for another project where unit test passes but with different versions: