1

i am using httpClient:

get(url: string, options?:HttpOptionsInterface): Observable<HttpResponse<any>> {

    return this.http.get(url, options).map((res: any) => {
        return res;
    }).catch((error: any) => {
        if (error.status === 401) {
            this.error401Handler();
        }
        return Observable.throw(error);
    });
}

and this is my HttpOptionsInterface:

export interface HttpOptionsInterface {
    headers?: HttpHeaders | {
        [header: string]: string | string[];
    };
    observe?: 'response';
    params?: HttpParams | {
        [param: string]: string | string[];
    };
    reportProgress?: boolean;
    responseType?: 'json';
    withCredentials?: boolean;
}

but i got error:

error TS2345: Argument of type 'HttpOptionsInterface' is not assignable to parameter of type '{ headers?: HttpHeaders | { [header: string]: string | string[]; }; observe?: "body"; params?: Ht...'.
Types of property 'observe' are incompatible. Type '"response"' is not assignable to type '"body"'.

sample stackblitz.

Fateme Fazli
  • 11,582
  • 2
  • 31
  • 48
  • 1
    Hi, The HTTPClient GET request options are optional, so you do not have to specify this unless you want to send parameters. Otherwise you can just put the URL of the API. – soumare Jan 16 '19 at 11:14
  • 3
    You have made your Interface with `observe` as optional, in that case it will consider it as `body` by default, if you want to have it as `response` make it compulsory – Ashish Ranjan Jan 16 '19 at 11:33
  • 1
    @xyz thank you, i actually needed this. – Fateme Fazli Jan 16 '19 at 11:47

1 Answers1

2

Seems like "observe" should be "body" and not "response" in your interface definition.

Gnujeremie
  • 570
  • 3
  • 17