fix(ivy): handle overloaded constructors in ngtsc (#34590)
Currently ngtsc looks for the first `ConstructorDeclaration` when figuring out what the parameters are so that it can generate the DI instructions. The problem is that if a constructor has overloads, it'll have several `ConstructorDeclaration` members with a different number of parameters. These changes tweak the logic so it looks for the constructor implementation. PR Close #34590
This commit is contained in:
@ -982,6 +982,30 @@ describe('di', () => {
|
||||
`This will become an error in v10. Please add @Injectable() to the "MyRootService" class.`);
|
||||
}
|
||||
});
|
||||
|
||||
it('should inject services in constructor with overloads', () => {
|
||||
@Injectable({providedIn: 'root'})
|
||||
class MyService {
|
||||
}
|
||||
|
||||
@Injectable({providedIn: 'root'})
|
||||
class MyOtherService {
|
||||
}
|
||||
|
||||
@Component({template: ''})
|
||||
class MyComp {
|
||||
constructor(myService: MyService);
|
||||
constructor(
|
||||
public myService: MyService, @Optional() public myOtherService?: MyOtherService) {}
|
||||
}
|
||||
TestBed.configureTestingModule({declarations: [MyComp]});
|
||||
const fixture = TestBed.createComponent(MyComp);
|
||||
fixture.detectChanges();
|
||||
|
||||
expect(fixture.componentInstance.myService instanceof MyService).toBe(true);
|
||||
expect(fixture.componentInstance.myOtherService instanceof MyOtherService).toBe(true);
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
describe('inject', () => {
|
||||
|
Reference in New Issue
Block a user