gpt4 book ai didi

angular - 类型 'MonoTypeOperatorFunction' 的参数不可分配给类型 'UnaryFunction, Observable>' 的参数

转载 作者:太空狗 更新时间:2023-10-29 17:24:33 29 4
gpt4 key购买 nike

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

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>'.

最佳答案

我发现我的代码有同样的错误:

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

TS2345:“MonoTypeOperatorFunction”类型的参数不可分配给“OperatorFunction”类型的参数。

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

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

现在你有错误

算术运算的左侧必须是“any”、“number”类型,因此请确保这个烦人的过滤器获得正确的数据类型

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

但是现在代码停止工作了。最后,要解决此问题,请在开头将 of 更改为 from。

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

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

我认为,我的示例可以帮助您处理类似的问题。

关于angular - 类型 'MonoTypeOperatorFunction<any>' 的参数不可分配给类型 'UnaryFunction<Observable<any>, Observable<any>>' 的参数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51646369/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com