Property 'json' does not exist on type 'Object'

it been a while since I last use Ionic and I am trying to do login, but I ma getting this error 'Property ‘json’ does not exist on type ‘Object’. under res.json

return new Promise((resolve, reject) => {
      let headers = new HttpHeaders();
      headers = headers.set('Authorization',');
      headers = headers.set('Content-Type','');
      this.http.post(apiUrl, JSON.stringify(body), {headers: headers})
        .subscribe(res => {
          resolve(res.json());
        }, (err) => {
          reject(err);
        });
  });

The call to json() is no longer needed here, the result is already parsed.

1 Like

New httpClient by default calls res.json() implicitly and you don’t need to that manually yourself.

1 Like

While you’re fixing things, get rid of the pointless Promise and just do:

return this.http.post<WhateverTypeTheResultIs>(apiUrl, body);

There is no need for setting the content type explicitly, nor stringifying the body.

1 Like

but what if I want to covert to qs instead of JSON I still don’t have stringifying it?! + Is the place to find a tutorial or doc for all of this

Perhaps your server throws an error and send HTML or text as response back.

Sorry, I have no clue what “qs” is, but here is a tutorial on using HttpClient.