Angular Error: Property 'map' is not found in type 'OperatorFunction'

Code:

Using map and switchMap from 'rxjs/operators'.

 import { map, switchMap } from 'rxjs/operators';

Here is the canActivate code for route guard:

  canActivate(): Observable<boolean> {
    return this.auth.userObservable
      .pipe(switchMap((user: firebase.User) => this.userService.fetch(user.uid))
      .map((user) => user.isSeller));
  }

An error is encountered with message: Property 'map' does not exist on type 'OperatorFunction'. Screenshots provided below.

Attempt made: Attempting to wrap map within pipe but still facing issues.

canActivate(): Observable<boolean> {
    return this.auth.userObservable
      .pipe(switchMap((user: firebase.User) => this.userService.fetch(user.uid))
      .pipe(map((user) => user.isSeller)));
  }

The above syntax is throwing errors as well. Any insights on what may be causing this issue would be greatly appreciated. Thanks in advance!

Answer №1

The code snippet containing the map operator from RxJS must be enclosed within the pipe() method.

canActivate(): Observable<boolean> {
    return this.auth.userObservable
      .pipe(
        switchMap((user: firebase.User) => this.userService.fetch(user.uid)),
        map((user) => user.isSeller)
     )
  }

Answer №2

Remember to include all operators inside the pipe separated by commas.

 canActivate(): Observable<boolean> {
    return this.auth.userObservable
      .pipe(switchMap((user: firebase.User) => this.userService.fetch(user.uid))
      , map((user) => user.isSeller));
  }

Answer №3

The reason for the error message is due to calling map on the output of switchMap (which does not have a method named map), while mistakenly closing the parenthesis.

When using pipeable operators, it is common practice to chain them as arguments in the pipe function:

obs$.pipe(op1(...), op2(...), ..., opN(...));

To fix your code, you should rewrite it as follows:

canActivate(): Observable<boolean> {
    return this.auth.userObservable
      .pipe(
         switchMap((user: firebase.User) => this.userService.fetch(user.uid)),
         map(user => user.isSeller)
      );
}

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Record the success or failure of a Protractor test case to generate customized reports

Recently, I implemented Protractor testing for our Angular apps at the company and I've been searching for a straightforward method to record the pass/fail status of each scenario in the spec classes. Is there a simple solution for this? Despite my at ...

Utilizing Angular2 with Webpack in Visual Studio 2015

Is there a way to utilize Visual Studio 2015 alongside Webpack and Angular2? I have successfully created an Angular2 App with VS, but now that I've added Webpack to build my app, I would like to debug all of my code using IIS Express. I want to be abl ...

When merging multiple prop definitions using Object.assign in defineProps, Vue props can be made optional

I have defined a const called MODAL_OPTION_PROP to set common props for a modal: export const MODAL_OPTION_PROP = { modalOption: { type: Object as PropType<ModalOptionParams>, default: DEFAULT_MODAL_OPTION, }, }; I am trying to use it in ...

Mastering Firebase pagination with RxJS - the ultimate solution

I came across this helpful post on Cloud Firestore pagination with RXJS at Cloud Firestore - How to paginate data with RXJS While it is exactly what I need, I am struggling to understand how to implement the following code snippet: import { UsersService } ...

Rendering a sanitized string with interpolation in Angular 2

After receiving the string below: "Today's product of the day is {{product_code}} !" I took this string, sanitized it to bypass security restrictions using HTML this.DomSanitizer.bypassSecurityTrustHtml(str) and inserted it into my template using ...

What is the procedure for linking the value (<p>John</p>) to the mat form field input so that it displays as "John"?

Can I apply innerHTML to the value received from the backend and connect it to the matInput? Is this a viable option? ...

Experiencing difficulties while trying to showcase a PDF within the Expo Go app

I am currently developing a React Native application that requires the display of PDF files. I have tried two different methods, one using react-native-webview and the other with react-native-pdf, but both approaches are presenting challenges. This is how ...

Retrieving data and parameter data simultaneously from the ActivatedRoute

I am currently utilizing Angular and have a webpage where I need to send data to another page. Transmit an array of selected values Generate multiple records (associating with a model) this.activatedRoute.data.subscribe(({ model] }) => { setTim ...

Setting up project with local library installation in Angular 7 - Project configuration

I am currently working on an Angular application that consists of a core module and a shared module. The structure of my project is as follows: ./repo | projects | core | shared | src (my app) When I build libraries, the output folder is dist ...

Generate a list of items in typescript, and then import them into a react component dynamically

I have a variable that stores key/value pairs of names and components in a TypeScript file. // icons.tsx import { BirdIcon, CatIcon } from 'components/Icons'; interface IconMap { [key: string]: string | undefined; } export const Icons: IconM ...

Obtaining the attribute value from a custom tag in Angular: A comprehensive guide

I am currently working on creating a customized password component in Angular5. I am having difficulty obtaining the minimum and maximum attribute values required to validate the password. I attempted to retrieve the values using JavaScript's getAttr ...

What is the best method to locate an element<T> within an Array[T] when <T> is an enum?

I've recently started learning TypeScript and exploring its functionalities. I could use some assistance in deepening my understanding. Within our angular2 application, we have defined an enum for privileges as follows: export enum UserPrivileges{ ...

Looping inside a loop with Angular's ngFor

I am working on an Angular + Firebase app. Within one of my components, I am retrieving elements from the Firebase DB and binding them into a template using *ngFor: <div *ngFor="let comment of (comments | async)> <div>{{ comment.text }}< ...

Module 'csstype' not found

I am diving into the world of React with TypeScript. After setting up react and react-dom, I also installed @types/react and @types/react-dom which all went smoothly. However, a pesky error message keeps popping up: ERROR in [at-loader] ./node_modules/@t ...

Encountered issues with the BsModalService in displaying the modal functionality

I am encountering an issue while attempting to display a modal using a service. When I call the service from a button, everything works fine. However, I encounter an error when calling it from an error handler. TypeError: Cannot read property 'attach ...

Using TypeScript arrow functions to define parameters

When setting "noImplicitAny": true in TypeScript, you may encounter the following errors: Parameter 'x' implicitly has an 'any' type This error can occur with the code snippet: .do(x => console.log(x)); Another error you might s ...

Steps for developing a Global service in Angular

I've come across many discussions on global angular services, but none seem to truly embody the concept of "global". I'm curious if it's feasible to develop a service that doesn't require importing everywhere it's used (i.e. truly ...

The juvenile entity does not align with the foundational entity [typescript]

After setting "strict": true in my tsconfig.json, I encountered compiler errors when attempting to run the code. To replicate and explore this issue further, you can try running the following code snippet. The problem arises when the child clas ...

Implementing conditional where clauses in Firestore queries with dynamic parameters

Consider this scenario: I have a dynamic filter list for my product list, and I want to send an HTTPS request to a cloud function based on the selected filters. However, when trying to set multiple conditional where clauses from that request... The multip ...

What is the best way to link multiple select tags in an HTML document?

I am working with a data grid that contains student information such as Name, Class, and Score. Each row has a checkbox for selection. The requirement is that when the user selects one or more rows and clicks on the "show information" Button, a new windo ...