RxJs pipe and lettable operator `map`: 'this' context of type 'void' is not assignable to method's 'this' of type 'Observable<{}>'

JavascriptTypescriptRxjs

Javascript Problem Overview


I have this very basic example that uses lettable operator map with pipe from [email protected]:

import { map } from 'rxjs/operator/map';

let o = of(1, 2, 3, 4).pipe(
    map((v) => v * 2)
);

But it produces the error Error:(34, 5) TS2684:The 'this' context of type 'void' is not assignable to method's 'this' of type 'Observable<{}>'. What's the problem here?

Javascript Solutions


Solution 1 - Javascript

Lettable instance operators should be imported from rxjs/operators:

import { map } from 'rxjs/operators';

As opposed to non-lettable equivalents which are imported from rxjs/operator:

import { map } from 'rxjs/operator/map';

To learn more about lettable operator read:

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionMax KoretskyiView Question on Stackoverflow
Solution 1 - JavascriptMax KoretskyiView Answer on Stackoverflow