3
votes

I have an error: Type 'Observable' is not assignable to type 'Observable'. Type 'Object' is not assignable to type 'boolean'.

  deleteUser(userId: string): Observable<boolean> {
    return this.httpClient
      .delete(url, this.getHttpOptions())
      .map(res => {
        return res;
      })
      .catch(this.handleError);
  }

I got the type of res as a boolean when I tried to print it.

3
Try that: return this.httpClient.delete<boolean>(...), and you won't need the mapDavid
This error should be thrown from different place. Check the code where you are using this deleteUser method. And make sure you have set Observable<boolean> in there too; Or you can try .delete<boolean>(url, this.getHttpOptions()); This should work toozgabievi

3 Answers

4
votes

At compile time, TypeScript doesn't know what actually comes from API call, it infers it from declarations and function signatures.

      .delete<boolean>(url, this.getHttpOptions())

should work.

(And yes, ditch the map).

1
votes

The type of res needs to be boolean, by default it will be any. Replace map by following :

map((res:boolean) => {
    return res;
  })
0
votes

You can fix it by removing your .map (which doesn't do anything):

deleteUser(userId: string): Observable<boolean> {
  return this.httpClient
    .delete(url, this.getHttpOptions())
    .catch(this.handleError);
}