"Utilizing Typescript with Angular NGRX, the actions$.pipe() method can lead to

I am currently facing an issue with ngrx/effects - specifically with a pipe being undefined. I have included a sample code snippet below that appears to be correct according to the compiler, but I am receiving an error in the browser stating that the pipe is undefined.

constructor(
    private actions$: Actions,
    private ethereumService: EthereumService
) { }

loadUser$ = createEffect(() =>
    this.actions$.pipe(
        ofType(loadAccountState),
        mergeMap(() => this.ethereumService.getAccountDetails()
            .pipe(
                map(setAccountStateCompleted),
                catchError(() => EMPTY)
            )
        )
    )
);

In my AppModule:

StoreModule.forRoot(reducers),
EffectsModule.forRoot([AccountEffects]),

EDIT: Strange enough, even this simplified example is producing the same error

logActions$ = createEffect(() =>
    this.actions$.pipe(
        ofType(AccountActions.loadAccountState),
        tap(action => console.log(action))
    ), { dispatch: false });

PS2. In addition, I am utilizing ActionReducerMap as my main reducer file imported to Root under the name reducers

import {
  createSelector,
  createFeatureSelector,
  ActionReducerMap,
} from '@ngrx/store';

import * as fromAccount from './account.reducer';

export interface State {
  account: fromAccount.State;
}

export const reducers: ActionReducerMap<State> = {
  account: fromAccount.updateAccountReducer,
};

export const selectAccountState = createFeatureSelector<fromAccount.State>('account');

//Account Selectors
export const selectCurrentUser = createSelector(
  selectAccountState,
  fromAccount.selectActiveAccount
);

If anyone can provide insight into what might be wrong with my code, I would greatly appreciate it. Thank you for your help

Answer №1

Depending on how the $actions is declared, the resulting code may vary when targeting ES2022 or newer versions.

To quickly resolve this issue, add the following to your tsconfig.json:

"compilerOptions": {
  {
    // ...
    "useDefineForClassFields": false
    // ...
  }
}

In the future, consider refactoring class initialization and avoiding the use of this flag.

For more information:

This issue may also arise when switching the compiler target to ES2022, causing some Jest tests to fail as a result.

Answer №2

If you're working with Angular version 15, make sure to include the following code:

actions$ = inject(Actions);

Ensure that your tsconfig file is configured to use ES2022 for this to work correctly.

Answer №3

To resolve the issue, I made a simple adjustment to my tsconfig.json file by switching the reference from ESNEXT to ES2020.
Check out the tsconfig keys here.

Since implementing this change, I've relocated my createEffect methods outside of the constructor within my effects file, and everything is now functioning properly.

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

Strategies for successfully passing and showcasing the result of a calculation on a fresh view or component within Angular

I have developed a basic calculator application with two main components: Calculator and Result. The Angular router is used to navigate between these components. Now, I am looking for a way to dynamically display the calculation result from the Calculator ...

Updating Angular component state based on route changes using a service

My component, named profile, is reliant on data from user.service. However, I'm facing an issue where the data does not update when the Route changes (triggered by a click using 'routerLink'). I aim to have the component fetch new data from ...

What is the solution for the warning "Solid's reactivity is broken when destructuring component props"?

Just starting out with SolidJS and encountering an issue with my UI setup import { render } from "solid-js/web"; import { createSignal, Show } from "solid-js"; import { createStore } from 'solid-js/store'; function Form() { ...

The argument represented by 'T' does not align with the parameter represented by 'number' and therefore cannot be assigned

I am confused as to why, in my situation, <T> is considered a number but cannot be assigned to a parameter of type number. Changing the type of n to either number or any resolves the issue. Error: https://i.sstatic.net/h1GE9.png Code: const dropF ...

Slider components in Angular 4/6 Material, allowing for time scale customization spanning across 24 hours

Currently, I am utilizing Angular Material to craft a slider specifically designed for a 24-hour range. My objective is to have the value of the slider displayed on the side. So far, the following functionalities are up and running: I can capture t ...

What steps do I need to take for the function to accurately determine the return type?

class Foo { name: string; constructor({name}: {name: string}) { this.name = name; } } class Bar<T extends Foo> { foo: T; constructor({foo}: {foo: T}) { this.foo = foo; } } class CustomFoo extends Foo { xxx: string; constr ...

Displaying Mat-error from response in Angular and Django user authentication process is not functioning as expected

Currently, I am working on the Signup page and facing an issue with handling 'if username already Exists'. I have successfully logged the Error message I want to display in the Console but it is not appearing on the Mat-error Label. This snippet ...

The NodeJS namespace appears to be missing

I'm currently utilizing Ionic2 in conjunction with socket.io Upon running ionic serve, I encounter the following error message in the terminal: TypeScript error: typings/globals/socket.io/index.d.ts(357,30): Error TS2503: Cannot find namespace &apos ...

Using Typescript and ThreeJS, include new elements to the environment within the loader

Can someone help me with the following code snippet? export class LandingPageComponent implements OnInit { scene: THREE.Scene; (...) ngOnInit() { this.scene = new THREE.Scene(); var loader = new THREE.JSONLoader(); loader.load("../../assets/fire_lion.j ...

How to Customize Bootstrap Colors Globally in Angular 4 Using Code

I am interested in developing a dynamic coloring system using Angular. I have set up a service with four predefined strings: success, info, warning, and danger, each assigned default color codes. My goal is to inject this service at the root of my applicat ...

Tips for assigning dynamic #id(*ngFor) and retrieving its value in Angular2

In my HTML file, I have the following code snippet: <tr *ngFor="let package of packages"> <td *ngFor="let coverage of coverages"> <input type="hidden" #dynamicID [value]="coverage.id"> <-- Include an identifier with the vari ...

The type "AppRouterInstance" cannot be assigned to type "nextRouter"

Within my Next.js project, a registration form is included as seen below: "use client"; import * as React from "react"; import { zodResolver } from "@hookform/resolvers/zod"; import { useForm } from "react-hook-form" ...

Cannot create service instance from external module

Including an external module (ExternalModule) in my AppModule, I noticed that the constructor of a service within the external module is not being called. Here's a snippet of the code from both modules and the service: // AppModule import { BrowserMo ...

Testing the NestJS service with a real database comparison

I'm looking to test my Nest service using a real database, rather than just a mock object. While I understand that most unit tests should use mocks, there are times when testing against the actual database is more appropriate. After scouring through ...

Steps to display a modal within an inactive tab:

I have been using ngx-bootstrap tabset, although I believe this issue could apply to all bootstrap tabs as well. <tabset> <tab class='active'> <angular-modal-component> </angular-modal-component> </tab> <tab> & ...

The data type 'string | null | undefined' cannot be assigned to the data type 'string | undefined'

In my Angular application using Typescript, I have the following setup: userId?: number; token?: string; constructor(private route: ActivatedRoute) { this.route.queryParamMap.subscribe( (value: ParamMap) => { this.userId = val ...

Utilize a generic approach for every element within a union: Transforming from Some<1 | 2 | 3> to individual Some<1>, Some<2>, or Some<3> instances

As I was unable to create a concise example for my issue, this is a general rendition of it. I am facing a scenario where the "sequence of application" is vital in nested generics. type Some<A> = {type: A} type Union1 = Some<1 | 2 | 3> type Uni ...

Is there a way to execute the run function of a different Component in Angular 7 without causing the current

Is there a way to execute the ngOnInit() function from one component inside another component without needing to refresh the existing page? ...

Navigating with the Angular router to a child route is causing a redirection to the 404

I'm facing a challenge with navigating to a child component from the parent view. This is how my app-routing configuration looks: const routes: Routes = [ { path: '', redirectTo: 'home', pathMatch: 'fu ...

What is the recommended approach for storing and retrieving images in the Angular 5 framework?

I have an Angular 5 app that utilizes Java rest services. The Java application stores images in a folder located outside of the Java app itself. Now, my goal is for the Angular app to be able to read these images. Although it makes sense to store them outs ...