typedi icon indicating copy to clipboard operation
typedi copied to clipboard

fix: Using constructor injection from base class

Open anton-johansson opened this issue 3 years ago • 0 comments

Description

I have a base class that handles a lot of common logic that my sub classes use. The base class accepts a single dependency, and is only used by the base class. So having a constructor in the sub-class is redundant (and my xo warns about it).

Minimal code-snippet showcasing the problem

abstract class AbstractThing {
    private readonly myDependency: MyDependency;

    constructor(myDependency: MyDependency) {
        this.myDependency = myDependency;
    }
}

@Service()
class RealThing extends AbstractThing {
}

Expected behavior

I expect MyDependency to be injected properly, even without a constructor in the sub class.

Actual behavior

ContainerInstance seems to be injected instead of MyDependency.

anton-johansson avatar May 14 '21 12:05 anton-johansson