Ok, so I'm getting deep into TypeScript inheritance (specifically in Angular 11), and I've set up a BasePageComponent
to provide all the necessary functions and services that exist across pages.
The issue I've run into, is that now my base is getting bloated, because there are services that are used only on one or two pages, but in order to extend the base, we have included those in the base.
export class BasePageComponent {
constructor(
public uiPopupService: UiPopUpService,
public loaderService: LoaderService,
public questionService: QuestionService,
public aBunchOfOthers: OTHERS,
public exampleOneOffService: ExampleOneOffService
) {}
}
I realize that it would be more performant to repeat all the injected services, and then pass them all up to BasePageComponent
as so:
export class ChildPageComponent extends BasePageComponent {
constructor(
public uiPopupService: UiPopUpService,
public loaderService: LoaderService,
public questionService: QuestionService,
public aBunchOfOthers: OTHERS,
private exampleOneOffService: ExampleOneOffService
) {
super(uiPopupService, loaderService, questionService, aBunchOfOthers);
}
}
I will do the above, if there's no other way, but I have as hinted at in the sample code, I have a bunch of other micro services that are included in the base (like 15-20), so I want to be able to do something like this, where I just declare the one additional service, and still inherit all the others from the parent class, but I am not seeing a way to do this.
export class ChildPageComponent extends BasePageComponent {
constructor(private otherExampleService: OtherExampleService){
super()
};
}
Does this pattern exist and I'm just not googling the right keyword?