Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Type 'Observable<TData>' is missing the following properties from type 'Observable<TData>': map… for generic implementation

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…

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

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';
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading