Angular 4/5 HttpClient: Argument of type string is not assignable to 'body'

前端 未结 4 1471
醉酒成梦
醉酒成梦 2020-11-30 05:58

The Angular docs say:

The response body doesn\'t return all the data you may need. Sometimes servers return special headers or status codes to indic

4条回答
  •  慢半拍i
    慢半拍i (楼主)
    2020-11-30 06:32

    You have to inline the options. See github ticket #18586, entry by alxhub on August 9 2017.

    Typescript needs to be able to infer the observe and responseType values statically, in order to choose the correct return type for get(). If you pass in an improperly typed options object, it can't infer the right return type.

    login(credentials: Credentials): Observable {
        return this.httpClient.post(`${environment.USER_SERVICE_BASE_URL}`,
          {'username': credentials.username, 'password': credentials.password}, {
          headers: new HttpHeaders({'Content-Type': 'application/json'}),
          observe: 'response'
        })
          .map((res) => ...
    

提交回复
热议问题