# \[ts\] Property 'subscribe' does not exist on type '(res: any) =\> any'

**URL:** <https://forum.ionicframework.com/t/ts-property-subscribe-does-not-exist-on-type-res-any-any/112627>\
**Category:** ionic-v3\
**Created:** [November 19, 2017, 11:40am UTC](https://forum.ionicframework.com/t/ts-property-subscribe-does-not-exist-on-type-res-any-any/112627 "2017-11-19T11:40:29Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![newtonmunene](https://sea1.discourse-cdn.com/ionicframework/user_avatar/forum.ionicframework.com/newtonmunene/32/125386_2.png) [@newtonmunene](https://forum.ionicframework.com/u/newtonmunene)\
**Post date:** [November 19, 2017, 11:40am UTC](https://forum.ionicframework.com/t/ts-property-subscribe-does-not-exist-on-type-res-any-any/112627/1 "2017-11-19T11:40:29Z")

</div>

Hi guys,

I’m working on a http provider. The issue is with the subscribe module after mapping the json response.  
Here is the code for the provider and a screenshot:

```auto
import { HttpClient } from '@angular/common/http';
import { Injectable } from '@angular/core';
import { Http } from '@angular/http';
import { Observable } from 'rxjs/Observable';
import 'rxjs/add/operator/map';

/*
  Generated class for the PostsProvider provider.

  See https://angular.io/guide/dependency-injection for more info on providers
  and Angular DI.
*/
@Injectable()
export class PostsProvider {
  data: any = null;

  constructor(public http: HttpClient) {
    console.log('Hello PostsProvider Provider');
    // this.load();
  }

  load() {
    if (this.data) {
      // already loaded data
      return Promise.resolve(this.data);
    }

    // don't have the data yet
    return new Promise(resolve => {
      // We're using Angular HTTP provider to request the data,
      // then on the response, it'll map the JSON data to a parsed JS object.
      // Next, we process the data and resolve the promise with the new data.
      this.http.get('https://randomuser.me/api/?results=10')
        .map((res => res.json())
        .subscribe(data => {
          // we've got back the raw data, now generate the core schedule data
          // and save the data for later reference
          this.data = data.results;
          resolve(this.data);
        }));
    });
  }

}

```

 ![image](https://global.discourse-cdn.com/ionicframework/original/3X/b/d/bdc69688b13c4d6a98e1cf43248b7c7cf6349bdb.png)

 ![Screenshot (8)](https://global.discourse-cdn.com/ionicframework/original/3X/4/d/4d10f17f6de021220f63ca541e9965061e33f842.png)

I’m new to ionic and still learning. I’ve been following tutorials but now i seem to be stuck. Ive tried looking at posts from this and other forums but none have worked for me. Anyone please help. I’m sure its just a small error but it’s huge when you’re learning.

---

<div class="post-metadata">

**Author:** ![reedrichards](https://avatars.discourse-cdn.com/v4/letter/r/34f0e0/32.png) [@reedrichards](https://forum.ionicframework.com/u/reedrichards)\
**Post date:** [November 19, 2017, 11:52am UTC](https://forum.ionicframework.com/t/ts-property-subscribe-does-not-exist-on-type-res-any-any/112627/2 "2017-11-19T11:52:26Z")

</div>

> [@newtonmunene](#):
>
> .map((res =\> res.json())

Maybe a typing mistake, shouldn’t one parenthesis be removed?

```
.map(res => res.json())

```

or

```
.map((result: Response)=> res.json())

```

---

<div class="post-metadata">

**Author:** ![newtonmunene](https://sea1.discourse-cdn.com/ionicframework/user_avatar/forum.ionicframework.com/newtonmunene/32/125386_2.png) [@newtonmunene](https://forum.ionicframework.com/u/newtonmunene)\
**Post date:** [November 19, 2017, 11:55am UTC](https://forum.ionicframework.com/t/ts-property-subscribe-does-not-exist-on-type-res-any-any/112627/3 "2017-11-19T11:55:28Z")

</div>

I removed the parenthesis and this is what i got:

 ![Screenshot (9)](https://global.discourse-cdn.com/ionicframework/original/3X/9/d/9d2c7eea7a5bd64ad30ec64f4e9c97069773e031.png)

---

<div class="post-metadata">

**Author:** ![reedrichards](https://avatars.discourse-cdn.com/v4/letter/r/34f0e0/32.png) [@reedrichards](https://forum.ionicframework.com/u/reedrichards)\
**Post date:** [November 19, 2017, 11:56am UTC](https://forum.ionicframework.com/t/ts-property-subscribe-does-not-exist-on-type-res-any-any/112627/4 "2017-11-19T11:56:57Z")

</div>

Then the 2nd solution I mentioned above:

```
.map((result: Response)=> res.json())
```

---

<div class="post-metadata">

**Author:** ![reedrichards](https://avatars.discourse-cdn.com/v4/letter/r/34f0e0/32.png) [@reedrichards](https://forum.ionicframework.com/u/reedrichards)\
**Post date:** [November 19, 2017, 11:58am UTC](https://forum.ionicframework.com/t/ts-property-subscribe-does-not-exist-on-type-res-any-any/112627/5 "2017-11-19T11:58:37Z")

</div>

Wait!

Just noticed now, you are using the new http client

```
import { HttpClient } from '@angular/common/http';

```

The you could delete the .map at all, it isn’t needed anymore

“old” HttpModule:

```
this.http.get('https://randomuser.me/api/?results=10')
    .map((res : Response) => res.json())
    .subscribe(data => {
      this.data = data.results;
      resolve(this.data);
    }));

```

“new” HttpClientModule:

```
 this.http.get('https://randomuser.me/api/?results=10')
    .subscribe(data => {
      this.data = data.results;
      resolve(this.data);
    }));

```

or with params (?)

```
 let params: HttpParams = new HttpParams();
params = params.set('results', 10);

this.http.get('https://randomuser.me/api/, {params: params})
    .subscribe(data => {
      this.data = data.results;
      resolve(this.data);
    }));
```

---

<div class="post-metadata">

**Author:** ![newtonmunene](https://sea1.discourse-cdn.com/ionicframework/user_avatar/forum.ionicframework.com/newtonmunene/32/125386_2.png) [@newtonmunene](https://forum.ionicframework.com/u/newtonmunene)\
**Post date:** [November 19, 2017, 12:02pm UTC](https://forum.ionicframework.com/t/ts-property-subscribe-does-not-exist-on-type-res-any-any/112627/6 "2017-11-19T12:02:27Z")

</div>

Thanks.  
Dont i need it to get the json data or something?

Here’s what happens when i remove it:

 ![Screenshot (11)](https://global.discourse-cdn.com/ionicframework/original/3X/4/0/4078db0644b2dc7581b69d6e21f1f2a06ad09277.png)

---

<div class="post-metadata">

**Author:** ![reedrichards](https://avatars.discourse-cdn.com/v4/letter/r/34f0e0/32.png) [@reedrichards](https://forum.ionicframework.com/u/reedrichards)\
**Post date:** [November 19, 2017, 12:05pm UTC](https://forum.ionicframework.com/t/ts-property-subscribe-does-not-exist-on-type-res-any-any/112627/7 "2017-11-19T12:05:34Z")

</div>

That’s a typescript error displayed from your editor I guess, no?

When you set a `type` or `any` to the results, do the error still pop?

```
this.http.get('https://randomuser.me/api/?results=10')
.subscribe((data:any) => {
  this.data = data.results;
  resolve(this.data);
}));

```

here an example from my app:

```
let params: HttpParams = new HttpParams();
params = params.set('limit', '1');
params = params.append('another_param', '1');

this.httpClient.get('https://....', {params: params})
            .subscribe((results: Something[]) => {
                resolve(results);
            }, (errorResponse: HttpErrorResponse) => {
                reject(errorResponse);
            });

```

where `Something` is a `class` or an `interface` like:

```
export class Something {
    id: string;
}
```

---

<div class="post-metadata">

**Author:** ![newtonmunene](https://sea1.discourse-cdn.com/ionicframework/user_avatar/forum.ionicframework.com/newtonmunene/32/125386_2.png) [@newtonmunene](https://forum.ionicframework.com/u/newtonmunene)\
**Post date:** [November 19, 2017, 12:09pm UTC](https://forum.ionicframework.com/t/ts-property-subscribe-does-not-exist-on-type-res-any-any/112627/8 "2017-11-19T12:09:17Z")

</div>

After setting the type there’s no errors. But the app isn’t displaying the data i want it to. It might be another issue. I’ll get back. Thanks so much

---

<div class="post-metadata">

**Author:** ![mhartington](https://sea1.discourse-cdn.com/ionicframework/user_avatar/forum.ionicframework.com/mhartington/32/137757_2.png) [@mhartington](https://forum.ionicframework.com/u/mhartington)\
**Post date:** [July 19, 2021, 10:03pm UTC](https://forum.ionicframework.com/t/ts-property-subscribe-does-not-exist-on-type-res-any-any/112627/9 "2021-07-19T22:03:28Z")

</div>


