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:
crisbeto
2019-12-29 10:50:19 +02:00
committed by atscott
parent 3113bb7ad2
commit a7ca658d68
5 changed files with 115 additions and 3 deletions

View File

@ -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', () => {