typedi icon indicating copy to clipboard operation
typedi copied to clipboard

fix: inject the right value in sub-class constructor params

Open 2betop opened this issue 4 years ago • 2 comments

Description

please just see the code below.

Minimal code-snippet showcasing the problem

it('should inject the right value in subclass constructor params', function () {
    function CustomInject(value: any) {
      return function (target: Constructable<any>, propertyName: string, index: number) {
        Container.registerHandler({
          object: target,
          propertyName: propertyName,
          index: index,
          value: containerInstance => value,
        });
      };
    }

    @Service()
    class SuperService {
      constructor(@CustomInject(888) readonly num: number) {}
    }

    @Service()
    class SubService extends SuperService {
      constructor(@CustomInject(666) num: number) {
        super(num);
      }
    }

    expect(Container.get(SuperService).num).toBe(888);
    expect(Container.get(SubService).num).toBe(666);
  });

Expected behavior

expect(Container.get(SubService).num).toBe(666);

Actual behavior

the actual value is 888

2betop avatar Apr 27 '21 03:04 2betop

This has been fixed and will be released in the next version.

NoNameProvided avatar Jan 13 '22 16:01 NoNameProvided

I keep the issues open on purpose until the fix is released so people can see it. I will close it after release.

NoNameProvided avatar Jan 14 '22 07:01 NoNameProvided