RxJs 管道和可出租运算符“map":“void"类型的“this"上下文不可分配给“Observable<{}>"类型的方法的“this" [英] RxJs pipe and lettable operator `map`: 'this' context of type 'void' is not assignable to method's 'this' of type 'Observable<{}>'

查看:13
本文介绍了RxJs 管道和可出租运算符“map":“void"类型的“this"上下文不可分配给“Observable<{}>"类型的方法的“this"的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个非常基本的例子,它使用来自 rxjs@5.5 的可出租运算符 mappipe:

I have this very basic example that uses lettable operator map with pipe from 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' 不可分配给类型为 'Observable<{}>' 的方法的 'this'. 这里有什么问题?

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?

推荐答案

Lettable 实例操作符应该从 rxjs/operators 导入:

Lettable instance operators should be imported from rxjs/operators:

import { map } from 'rxjs/operators';

与从 rxjs/operator 导入的不可出租等价物相反:

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:

这篇关于RxJs 管道和可出租运算符“map":“void"类型的“this"上下文不可分配给“Observable&lt;{}&gt;"类型的方法的“this"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆