Angular 5 ngrx Effect is showing an error regarding the absence of an exported member called 'ofType'

Attempting to incorporate Effects into my ngrx state manager has been a challenge. I am currently utilizing Angular v5.2.1, ngrx v4.1.1, and rxjs v5.5.6. I experimented with the "older" approach, for instance:

@Effect() login$: Observable<Action> = this.actions$.ofType('LOGIN')
.mergeMap(action =>
  this.http.post('/auth', action.payload)
    // If successful, dispatch success action with result
    .map(data => ({ type: 'LOGIN_SUCCESS', payload: data }))
    // If request fails, dispatch failed action
    .catch(() => of({ type: 'LOGIN_FAILED' }))
);

However, I encountered an error stating

Property 'mergeMap' does not exist on type 'Actions<Action>'
. So, I switched to the new pipe method. The issue arises when attempting to import the ofType operator.

// ...
import { Action } from '@ngrx/store';
import { Effect, Actions, ofType } from '@ngrx/effects';

import { map, mergeMap, catchError } from 'rxjs/operators';
import { of } from 'rxjs/observable/of';

@Injectable()
export class WifiEffects {

  @Effect()
  getWifiData: Observable<Action> = this.actions$.pipe(
    ofType(WifiTypes.getWifiNetworks),
    mergeMap((action: GetWifiNetworks) =>
      this.mapService.getWifiNetworks().pipe(
        map((data: WifiNetworks) => new GetWifiNetworksSucc(data)),
        catchError(() => of(new GetWifiNetworksErr()))
      )),
  );

  constructor (
    private actions$: Actions,
    private mapService: GoogleMapDataService
  ) {}

}

An error message is displayed saying

Module '".../node_modules/@ngrx/effects/effects"' has no exported member 'ofType'.
Are there any suggestions?

Answer №1

Upon reviewing the @ngrx/effects API, it seems that there is no indication of a lettable version being implemented for ofType. Therefore, the second implementation mentioned may not function as intended (particularly when ofType is used within the pipe).

The first implementation simply requires an import statement for mergeMap.

import 'rxjs/add/observable/mergeMap';

In addition, imports for map and catch are likely needed as well.

import 'rxjs/add/observable/map';
import 'rxjs/add/observable/catch';

If using ofType with pipe, the following approach should work:

@Effect()
getWifiData: Observable<Action> = 
  this.actions$.ofType(WifiTypes.getWifiNetworks)
    .pipe(
      mergeMap((action: GetWifiNetworks) =>
      ...

This is because ofType() returns an Observable that already includes .pipe in its prototype.


Footnote

After examining the source code on github (as of Jan 22, 2018), I came across an export for lettable ofType located here platform/modules/effects/src/index.ts.

However, upon installing with @ngrx/effects@latest (which installs version 4.1.1), I could not find this export reference in the installed node_modules folder.

Furthermore, attempting to use

import { ofType } from '@ngrx/effects';
in my component also did not work.

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

When utilizing the package, an error occurs stating that Chart__default.default is not a constructor in chart.js

I have been working on a project that involves creating a package with a react chart component using chart.js. Everything runs smoothly when I debug the package in storybook. However, I encountered an error when bundling the package with rollup, referenc ...

A guide on activating the <b-overlay> component when a child triggers an Axios request in vue.js

Is there a way to automatically activate the Bootstrap-vue overlay when any child element makes a request, such as using axios? I am looking for a solution that will trigger the overlay without manual intervention. <b-overlay> <child> ...

define a function with default arguments and a callback

When working with a JavaScript library, I encountered an issue where I needed to define my callback functions within an object. The goal was to include default parameters in the arguments of these callback functions stored in a TypeScript object. Here is a ...

The performance of Angular's ng serve feature is not meeting expectations

I'm currently facing an issue while trying to run my Angular application using ng serve. The ng build command works without any problems, but I encounter issues when I try to run the server (I also tried using npm start). View ngserve response I atte ...

Tips for retrieving the value of a dynamically generated input field in Angular

After creating an empty hash map of a 'question' object in Angular based on the number of questions provided on the previous page, I am now displaying the 'question' objects from the hash map when the page loads. My goal is to retrieve ...

The Ionic 5 app features a white iframe that functions perfectly on the web platform

Whenever I run my web application's function, the iframe is displayed. However, on Android, all I see is a white screen. Can anyone assist with resolving this issue? HMTL html <ion-content> <ion-button expand="full" color="warning" (clic ...

Tips for viewing the console log in PhpStorm while executing an Angular application

I'm using Angular in a PhpStorm IDE. My code is full of "console.log" calls, and I've declared it as declare var console: Console; which is defined in an interface called Console from the lib.dom.d.ts library. But where can I see these log mess ...

A guide to accessing the value of a web.config appsetting key in a Type Script service class

I am currently working on an Angular 2 application in Visual Studio 2015. In my project, I need to retrieve the app setting value from web.config in a TypeScript file (service.ts). Despite searching online and reading various resources, I have not been ab ...

Creating both Uniform and Varying drawings on a single webGL canvas

My goal is to create this specific illustration. https://i.sstatic.net/5AfdW.png This project requires the usage of TypeScript. The Code: The code is organized across multiple files. Within the scenegraph file, there's a function that visits a gro ...

Tips on instructing TypeScript to view a parameter as a namespace instead of a class, especially when they share the same name - gRPC

Apologies for the lengthy title... I am in the process of developing a basic crud system using gRPC and typescript. My issue lies in the fact that the auto-generated file creates a class and a type for each parameter in my protoFile. For example, the User ...

Is it necessary to transmit rule specifics to Stepfunctions?

Is it feasible to achieve what I'm attempting, or am I starting with an impossible task? When a Event Bridge Rule is triggered by an added event pattern, like shown below, should the detailed information be included in the step input? const rule = ne ...

Tips on assigning the ng-content of an Angular component within storybook

Trying to incorporate an Angular component that utilizes <ng-content> into Storybook has proven challenging due to difficulties specifying the content with a variable. The current code setup is as follows: import {Header1Component} from './head ...

Jasmine reported an error with the DomSanitizer Dependency Injection

I'm currently facing a challenge testing a basic component using jasmine that includes the constructor provided below constructor(public sanitizer: DomSanitizer) { } Within my test case, I've set up a testBed as follows: describe("Component: m ...

The HTMLElement type does not include the Ionic typescript property

I am currently using Ionic v3 with TypeScript. My goal is to store the file_url in an array after checking if its width is equal to twice its height. However, I am encountering an error: The 'name_array' property does not exist on the ' ...

What impact do passing children have on the occurrence of Typescript errors?

Recently, I came across a peculiar situation where the Typescript compiler appeared to be confused by passing the children prop to a component, leading to unsafe behavior. I am looking to create a component that can only accept the subtitle (text) and sub ...

Advantages of optimizing NodeJS/TypeScript application by bundling it with webpack

Currently, I am working on a Node/Express application and I am interested in incorporating the most recent technologies. This includes using TypeScript with node/Express along with webpack. I have a question: What advantages come with utilizing webpack t ...

Compilation issues encountered while running TypeScript in Dockerfile

I am encountering an issue with my Dockerfile during the TypeScript compilation step. Below is the snippet of code where it fails: FROM node:12 WORKDIR /usr/src/app # SETUP COPY package.json . COPY tsconfig.json . COPY src . RUN npm install -g yarn@^1. ...

What is the proper way to invoke an instance method through an inherited method using its name and ensuring the arguments are correctly typed?

We have created a foundational class that will be extended numerous times. Our goal is to implement an `exec` method on this base class, which will take the name and arguments of a method from a derived class and execute it. However, we are encountering a ...

What is the method for retrieving all documents that contain an array field with at least one object-element having a property value of 'X'?

I have a collection of MongoDB documents structured like this: { "group": "P32666", "order": [{ "_id": { "$oid": "5e8e9b40e7999f6b90fd88bf" }, "name": "Dmitriy A", "login": "example", "password": "example", "email": "exampl ...

Ways to specify DOM as potentially being undefined

My team and I are currently in the process of building a new Vue SSR application using Nuxt within a monorepo setup. We have organized the Nuxt app as a package, with another package serving as our component library. While we are relatively new to Typescri ...