我有一个非常基本的例子,它使用可出租运算符 map
与 pipe
来自 rxjs@5.5
:
import { map } from 'rxjs/operator/map';
let o = of(1, 2, 3, 4).pipe(
map((v) => v * 2)
);
但它会产生错误 Error:(34, 5) TS2684:The 'this' context of type 'void' is not assignable to method's 'this' of type 'Observable<{}>'.
这里有什么问题?
最佳答案
应从 rxjs/operators
导入可出租实例运算符:
import { map } from 'rxjs/operators';
与从 rxjs/operator
导入的不可出租的等价物相反:
import { map } from 'rxjs/operator/map';
要了解有关可出租运算符的更多信息,请阅读:
关于javascript - RxJs 管道和可出租运算符 `map` : 'this' context of type 'void' is not assignable to method's 'this' of type 'Observable<{}>' ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47198706/