March 2, 2018
The ‘this’ context of type ‘void’ is not assignable to method’s ‘this’ of type ‘Observable<{}>‘.
If you are experiencing this error – usually something with your RxJS imports is wrong. So you should go through them manually or simply delete all imports from RxJS in the corresponding file and let the IDE generate them again.
Something broken could look like this:
1 |
import {map} from 'rxjs/add/operator/map'; |
Better working might be:
1 |
import {map} from 'rxjs/operators'; |
What is happening?
RxJS switched from monkey patching to the import of pipeable operators (also known as lettable operators).
toPromise
Another reason might be a falsely used toPromise(). It is no longer available as pipeable operator but is now attached to the observable directly.
1 2 3 |
import {toPromise} from "rxjs/operator/toPromise"; this.sth$.pipe(map(it => it.value()), toPromise()); |
Should be:
1 |
this.sth$.pipe(map(it => it.value()).toPromise()); |