javascript - RxJs 管道和可出租运算符 `map` : 'this' context of type 'void' is not assignable to method's 'this' of type 'Observable<{}>'

标签 javascript typescript rxjs

我有一个非常基本的例子,它使用可出租运算符 mappipe来自 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/

相关文章:

javascript - 从 chrome.bookmarks 获取随机 url 并将其加载到 newTab

javascript - 变量值发生变化(根据alert())但被插件代码忽略?

javascript - 在opencart 1.5.5.1中不使用图像管理器上传图像

javascript - 如何像 console.log 一样对任何类型的值进行字符串化?

typescript - 源映射(用于浏览器扩展)在 Chrome 75、Edge 77 中对我不起作用

javascript - 将带标签的模板文字绑定(bind)到外部对象

angular - 如何检查多条件以将 observable 与 rxjs 连接起来

javascript - 创建简单的角色游戏

javascript - 从数组中生成 Angular reducer

javascript - 从 Angular2/Typescript 中的 rxJs 复制响应数据