0

I am getting this error,

Argument of type 'OperatorFunction<APISearch[], APISearch[]>' is not assignable to >parameter of type 'OperatorFunction<Object, APISearch[]>'.
The 'Object' type is assignable to very few other types. Did you mean to use the 'any' type >instead?

search.servic.ts

public getTracksAndArtists(term: string): Observable<APISearch[]> {
    const searchUrl: string = `search?q=${ term }&type=track%2Cartist`;

    return this.globalService.getQuery(searchUrl).pipe(
      map((res: APISearch[]) => {
        if (!res) {
          throw new Error('Value expected!');
        } else {          
          console.log('res:', res);
          return res;
        }
      }),
      catchError((err) => {
        throw new Error(err.message);
      }));
  }

getQuery function

public getQuery(query: string) {
    // define common url
    const url: string = `https://api.spotify.com/v1/${query}`;

    // define header to specify token
    const headers = new HttpHeaders({
      'Authorization': 'Bearer BQAr2XNaHkRgSxk-lWKIUEjHTPT1pG7qj696yYQgdpTLKSuVL9oMGcENth0yynhRilrfN_FjFxtGd3f9poE'
    });

    // execute request
    return this.http.get(url, { headers });
  }

APISearch interface

export interface APISearch {
    artists: Artists;
    tracks: Tracks;
  }

Any help is appreciated. I did tried using any but I guess am doing it wrong.

1 Answers1

0

Try changing your getQuery function to specify what you expect returned by changing the last line...

return this.http.get<APISearch[]>(url, { headers });

That should help match it up by specifying what the returned Observable emits.

See the overload function signatures in Angular's HttpClient.get() documentation.

JSmart523
  • 2,069
  • 1
  • 7
  • 17