繁体   English   中英

RxJs管道和可调运算符`map`:'this'类型的'this'上下文不能赋值给'Observable <{}>'类型的方法'this'

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

我有一个非常基本的例子,它使用来自rxjs@5.5 piperxjs@5.5操作符map

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导入lettable实例运算rxjs/operators

import { map } from 'rxjs/operators';

与从rxjs/operator导入的非可释放等价物相反:

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

要了解有关lettable operator read的更多信息:

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM