typedi
typedi copied to clipboard
fix: inject the right value in sub-class constructor params
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
This has been fixed and will be released in the next version.
I keep the issues open on purpose until the fix is released so people can see it. I will close it after release.