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<{}>'
问题描述
我有一个非常基本的例子,它使用来自 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< {}>'类型的方法'this'的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!