Search code examples
angularservicerxjs

Property 'map' is missing in type 'Observable<any[]>'


I trying to create a service, however when i try and add an observable of any it throws the following error, Property 'map' is missing in type 'Observable<any[]>'.

Below is my service

import { Injectable } from '@angular/core';
import { HttpClient } from '@angular/common/http';
import { environment } from 'environments/environment';
import { Observable } from 'apollo-client/util/Observable';
import { catchError } from 'rxjs/operators';
import { throwError } from 'rxjs';

@Injectable({
  providedIn: 'root'
})
export class TestService {

  protected apiURL = 'http://localhost:3000';

  constructor(private http: HttpClient) {}

  getTestCount(): Observable<any[]> {
    return this.http
      .get<any[]>(`${this.apiURL}/test-count`)
      .pipe(
        catchError(err => {
          return throwError(new Error(err));
        })
      );
  }
}

Solution

  • That's probably an error because of using the wrong import statement.

    You might be looking for the following import

    import { Observable } from 'rxjs/Observable';

    For rxjs 6+

    import { Observable } from 'rxjs';