RxJs管道和lettable运算符`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<{}>'

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

问题描述

我有一个非常基本的例子,它使用来自 rxjs的带有 map pipe 的lettable operator map @ 5.5

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)
);

但它产生错误错误:(34,5)TS2684:The 'this'类型的'this'上下文不能分配给'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?

推荐答案

可以从 rxjs /运算符导入Lettable实例运算符:

Lettable instance operators should be imported from rxjs/operators:

import { map } from 'rxjs/operators';

与从 rxjs / operator <导入的非可出租等价物相反/ code>:

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

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

要了解有关lettable operator的更多信息,请阅读:

To learn more about lettable operator read:

  • RxJS: Understanding Lettable Operators

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

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