Home > front end >  Argument of type 'Observable<unknown>' is not assignable to parameter of type '
Argument of type 'Observable<unknown>' is not assignable to parameter of type '

Time:11-11

I'm trying to process an Observable in a method after a request via pipe (map) to use this corrected Observable in guard. But while writing the handler, I encountered the following error:

Argument of type 'Observable<unknown>' is not assignable to parameter of type 'OperatorFunction<Object, unknown>'.
  Type 'Observable<unknown>' provides no match for the signature '(source: Observable<Object>): Observable<unknown>'.

Function with problem:

  isAccessToLobby() {
    return this.http
      .get(`${environment.domain}${BackendRoutes.Lobby}`, this.httpOptions)
      .pipe(map((data) => data.allowAccess));
  }

The router:

router.get("/lobby", isAuth, (req, res) => {
  return res.json({
    allowAccess: true,
  });
});

Tried to define the Observable type for the argument, but didn't help.

CodePudding user response:

As discussed in the comments the import from rxjs-compat causes the error.

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

Importing the map function from rxjs solves the error.

    import { map } from 'rxjs/operators';
  • Related