In my package.json file, I've "rxjs": "~6.3.3" and "rxjs-compat": "^6.5.2".With this I'm trying to use the map() method in a service of my project

whenever, I'm running ng serve, I'm getting this error -

Error in node_modules/rxjs-compat/operator/shareReplay.d.s(2,10):error TS2305

1

There are 1 best solutions below

2
Seyed-Amir-Mehrizi On

in rxjs library version +6, simple map method does not work. you should do some steps. first you should import map method as a operator from rxjs library.

in your ts file you should write:

 import {map} from 'rxjs/operators'

then everywhere you wnat to use map method,before that you should use pipe method and inside that you should bring map method. for example imagine that you have a GET method to obtain the data from one endpoint. you should do like this:

  getAll(){

   return this.http.get(this.endpoint)
    .pipe(map(response=>{
     console.log(response)      ///the result is here
    });

i hope it works for you