mergeMap does not exist on type observable
Solution 1
That's correct, the "patch" style of operators has been removed since RxJS 6. You should better update your code to use only "pipeable" operators or install rxjs-compat
package that provides backwards compatibility with RxJS 5.
For more detailed description see official doc: https://github.com/ReactiveX/rxjs/blob/master/docs_app/content/guide/v6/migration.md
... more specifically this part: https://github.com/ReactiveX/rxjs/blob/master/docs_app/content/guide/v6/migration.md#backwards-compatibility
Solution 2
Thanks to the answer given by @martin, i was able to get it working with the new pipe
operations in rxjs6
. Here is my working code.
import {from, Observable} from 'rxjs';
import {mergeMap} from 'rxjs/operators';
export class Test {
public doSomething(): Observable<any> {
return from(...).pipe(mergeMap(...));
}
}
Solution 3
Import the individual operators, then use pipe instead of chaining.
import { map, filter, catchError, mergeMap } from 'rxjs/operators';
source.pipe(
map(x => x + x),
mergeMap(n => of(n + 1, n + 2).pipe(
filter(x => x % 1 == 0),
scan((acc, x) => acc + x, 0),
)),
catchError(err => of('error found')),
).subscribe(printResult);
Source: https://auth0.com/blog/whats-new-in-rxjs-6/
prolink007
I am a Computer Engineer. Things listed below are just a few things i am knowledgeable of: C/C++/C#, java, QT, Android, linux, Object Oriented, Assembly, computer architecture, MIPS, msp430, networking, html, php, css, mysql, sqlite, oracle, xsl, several interpreted languages
Updated on June 09, 2022Comments
-
prolink007 almost 2 years
I am trying to use
mergeMap
inrxjs6
and i am getting this error:Property 'mergeMap' does not exist on type 'Observable<{}>'
I have tried
import 'rxjs/add/operator/mergeMap';
and it is not working.What am i doing wrong?
import {from, Observable} from 'rxjs'; export class Test { public doSomething(): Observable<any> { return from(...).mergeMap(); } }
-
prolink007 almost 6 yearsThanks @martin. I used the provided information to fix my issue with the
pipe
operator. Posted my solution as well. -
Luis Armando almost 6 yearsThe doc links aren't working any more. Let's try to update your references @martin