Curious as to why my code is throwing an error. I have specified a type for the method
type ReturnObsFunc = (str?: string) => Observable<any>;
I am trying to create a map using a Map Object, but it seems to be not working correctly
private getFilterSource$(filterType: FilterType): Observable<any> {
const sourceMap = new Map<FilterType, AnotherFunc>([
[FilterType.SubClient, this._filtersService.getClients$],
[FilterType.Product, this._filtersService.getProducts$],
]);
return sourceMap.get(filterType);
//The error says: Type 'ReturnObsFunc' is missing certain properties expected by 'Observable<any>'
}
Although there is a solution with object map, I am interested in finding out if it can be achieved using Map.
private getFilterSource$(filterType: FilterType): Observable<any> {
const sourceMap = {
[FilterType.SubClient]: this._filtersService.getClients$,
[FilterType.Product]: this._filtersService.getProducts$,
};
return sourceMap[filterType]
}