Javascript RxJs 管道和可出租运算符“map”:“void”类型的“this”上下文不可分配给“Observable<{}>”类型的方法“this”

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/47198706/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-23 03:46:44  来源:igfitidea点击:

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

javascripttypescriptrxjs

提问by Max Koretskyi

I have this very basic example that uses lettable operator mapwith pipefrom [email protected]:

我有一个使用可出租经营者这个非常简单的例子mappipe来自[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?

但它产生错误Error:(34, 5) TS2684:The 'this' context of type 'void' is not assignable to method's 'this' of type 'Observable<{}>'.这里有什么问题?

回答by Max Koretskyi

Lettable instance operators should be imported from rxjs/operators:

可出租的实例运算符应从以下导入rxjs/operators

import { map } from 'rxjs/operators';

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

与从以下进口的不可出租等价物相反 rxjs/operator

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

To learn more about lettable operator read:

要了解有关可出租运算符的更多信息,请阅读: