An trying to make a generic data-sharing service for different components. However I get this code and unsure of how to resolve it:
Type ‘Observable’ is missing the following properties from type ‘Observable’: map, filter, reduce, flatMap, and 2 more.
I have tried using extends for the TData but I could only do one of the either map, filter, reduce…
Here is my code:
import { Injectable } from '@angular/core';
import { Observable } from '@apollo/client';
import { Subject } from 'rxjs';
@Injectable({
providedIn: 'root'
})
export class DataMessageServiceService<TData> {
private updateEvent$ = new Subject<TData>();
constructor() { }
public getUpdateEvent(): Observable<TData>
{
return this.updateEvent$.asObservable(); // <--- ERROR HERE
}
public pushUpdateEvent(data: TData)
{
return this.updateEvent$.next(data);
}
}
>Solution :
you are importing Observable from @apollo/client. As far as I know using Observable from the rxjs library is the right way. The Observable class in RxJS provides a number of operators such as map, filter, reduce, flatMap.
import { Observable } from 'rxjs';