i have this event management service in my angular application. i want to set the return type of the OnEvent() method dynamiclly and i want to set the type where i inject the service in my components. for example this is component A's constructor which injected the same service with two differnt return type as T. consructor( private goodEventManagerService: EventManagementService<Array<IGood>>, private customerEventManagerService: EventManagementService<ICustomer> ){ customerEventManagerService.emitEvent(EventManagementTypeEnum.CustomerChanged,null) goodEventManagerService.emitEvent(EventManagementTypeEnum.CustomerChanged , []) } import { Injectable, OnDestroy } from '@angular/core'; import { AsyncSubject, Observable, Subject } from 'rxjs'; import { IEventPayload } from '../models/event-management'; import { EventManagementTypeEnum } from '../enums/event-management-type'; @Injectable({ providedIn: 'any', }) export class EventManagementService<T> implements OnDestroy { private _eventSubject$:AsyncSubject<IEventPayload<T>> = new AsyncSubject<IEventPayload<T>>(); emitEvent(eventType: EventManagementTypeEnum, data: T):void { this._eventSubject$.next({ data: data, event: eventType }); this._eventSubject$.complete(); } onEvent(): Observable<IEventPayload<T>> { return this._eventSubject$.asObservable(); } ngOnDestroy(): void { this._eventSubject$.complete(); this._eventSubject$.unsubscribe(); } } is this possible in angular or even Typescript? i dont want to check for the type in every subscription. i tested it and the result is just the same return type as the first event emits. ngOnInit(): void { this.goodEventManagerService.onEvent().subscribe(res=>{ console.log("Cart Detail Component ---goodEventManagerService",res); }) this.customerEventManagerService.onEvent().subscribe(res=>{ console.log("Cart Detail Component ---customerEventManagerService",res); }) } Cart Detail Component ---goodEventManagerService {data: null, event: 'customer-changed'} ------------ Cart Detail Component ---customerEventManagerService {data: null, event: 'customer-changed'} as you can see the first data value is set to null and the second one is an empty array. but the result of both subscriptions are null the EventManagementService is declared in a Core module which is a root module as a Library. and the constructor is in a component called A and it is declared in an angular application using that internal library. how do i solve this? any idea? Continue reading...