How can I refactor this code using TypeScript generics? I have three methods here, and I would like to consolidate them into a single method that accepts type T in order to avoid redundant code.
private initializeComponentIframe<T>(componentType: Type<T>) {
const componentFactory = this.componentFactoryResolver.resolveComponentFactory(componentType);
this.dynamicIframeContent.clear();
const dynamicComponent = <T>this.dynamicIframeContent.createComponent(componentFactory).instance;
dynamicComponent.facade = this;
dynamicComponent.url = this.url;
dynamicComponent.initialize();
}
this.initializeComponentIframe(BlueComponent);
this.initializeComponentIframe(BlackComponent);
this.initializeComponentIframe(GreenComponent);