类型为"MonoTypeOperatorFunction< any>"的参数不能分配给类型'UnaryFunction< Observable< Observable",Observable< any>'的参数 [英] Argument of type 'MonoTypeOperatorFunction<any>' is not assignable to parameter of type 'UnaryFunction<Observable<any>, Observable<any>>'

查看:175
本文介绍了类型为"MonoTypeOperatorFunction< any>"的参数不能分配给类型'UnaryFunction< Observable< Observable",Observable< any>'的参数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试从rxjs 5迁移到6,但是我遇到了困难.当我尝试这个

i am trying to migrate from rxjs 5 to 6 but i am having difficulties. when i try this

this._connectivity.isOnline().pipe(first()).subscribe((state) => {
  this.syncCheck(user.uid);
});

我遇到此错误

Argument of type 'MonoTypeOperatorFunction<any>' is not assignable to parameter of type 'UnaryFunction<Observable<any>, Observable<any>>'.
  Types of parameters 'source' and 'source' are incompatible.
    Type 'import("/home/User/Desktop/projectname/node_modules/rxjs/Observable").Observable<any>' is not assignable to type 'import("/home/User/Desktop/projectname/node_modules/rxjs/internal/Observable").Observable<a...'.
      Property 'map' is missing in type 'Observable<any>'.

推荐答案

我在我的代码中发现了相同的错误:

I found the same error with my code:

let source = of([1, 2, 3, 45, 56, 7, 7])
    .pipe(
        filter((x: number) => x % 2 == 0)
    );

TS2345:"MonoTypeOperatorFunction"类型的参数不能分配给"OperatorFunction"类型的参数.

TS2345: Argument of type 'MonoTypeOperatorFunction' is not assignable to parameter of type 'OperatorFunction'.

要解决此问题,请从过滤器功能中删除类型

To fix this, remove type from filter function

 filter(x => x % 2 == 0)

现在您有错误

算术运算的左侧必须为"any","number"类型,因此请确保此烦人的过滤器获取正确的数据类型

The left-hand side of an arithmetic operation must be of type 'any', 'number', so make sure, that this annoying filter gets correct data type

filter(x => Number(x) % 2 == 0) // parse element to number

但是现在代码停止工作了.最后,要解决此问题,请从一开始就将from更改为.

But now code stops work. Finally, to fix this, change of to from, at the beginning.

let source = from([1, 2, 3, 45, 56, 7, 7])
    .pipe(
        filter((x: number) => Number(x) % 2 === 0)
    )

let source = of(1, 2, 3, 45, 56, 7, 7)
.pipe(
        filter((x: number) => Number(x) % 2 === 0)
    )

所以,导致错误的原因是我的初始数据结构.

So, cause of error was my initial data structure.

我认为,我的示例可以帮助您解决类似的问题.

I think, that my example can help you with dealing similar problems.

这篇关于类型为"MonoTypeOperatorFunction&lt; any&gt;"的参数不能分配给类型'UnaryFunction&lt; Observable&lt; Observable&quot;,Observable&lt; any&gt;'的参数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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