Issue
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);
});
i am getting this error
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>'.
Solution
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: 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)
Now you have error
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
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)
)
or
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.
Answered By - Kamil Naja
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.