You cannot assign the type 'void' to the type 'ObservableInput<Action>'

I'm encountering a type error when I attempt to dispatch an observable of actions within my effect. The error message I'm receiving is as follows:

@Effect()
    rideSummary$: Observable<Action> = this.actions$.pipe(
        ofType<GetRideSummary>(RideActionTypes.GetRideSummary),
        map(action => action.payload),
        switchMap(payload => {
            const { ride, passenger } = payload;
            const allPassengers = [...ride.passengers, passenger];
            this.store.dispatch(new SetLoading);
            return this.directionService.computeRideRouteSummary(ride, allPassengers)
            .then((summary: RideRouteSummary) => {
                const updatedRoute = Geometry.newFromData({
                    type: Geometry.LINE_STRING,
                    coordinates: summary.route
                });

                const totalTime = summary.totalTime;
                const arrivalTime = ride.type === Ride.TYPE_TOWORK ?
                    ride.hour :
                    ride.hour + summary.totalTime;
                const departureTime = ride.type === Ride.TYPE_TOWORK ?
                    ride.hour - summary.totalTime :
                    ride.hour;
               this.store.dispatch(new UnsetLoading);
               return this.store.dispatch(new GetRideSummarySuccess({
                    updatedRoute,
                    totalTime,
                    arrivalTime,
                    departureTime
                }));
                }
            ).catch(error => {
                this.store.dispatch(new UnsetLoading);
                catchError(() => of(new HandleError(error)));
            });
        })
    );

The error message states:

Unable to assign an argument of type "(payload: {ride: Ride; passenger: Passenger;}) => void" to the type parameter "(value: {ride: Ride; passenger: Passenger;}, index: number) => ObservableInput <Action> ".
The type 'void' cannot be assigned to the type 'ObservableInput <Action>'.

I'm unsure about what exactly is causing the issue in the code. It appears to be related to the promise. Any assistance would be greatly appreciated.

Answer №1

When it comes to effects, it is defined as @Effect() which means it expects an Action. One quick but temporary solution is to define your effect as @Effect({dispatch: false}). A more appropriate solution would be to eliminate all store dispatches in your effect and instead return an action.

For example:

switchMap(payload => {
  this.store.dispatch(new FooBar());
}

You can refactor it to:

switchMap(payload => {
  return new FooBar();
}

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

Suddenly encountered issue when working with TypeScript Interfaces while integrating Quicktype 'allOf'

Our transition from using JSON Type Definition to JSON Schema includes the utilization of Quicktype to convert JSON Schemas into TypeScript Types. While Quicktype has been effective in most cases, it seems to struggle with converting Discriminators and mor ...

Implementing Express.js allows for the seamless casting of interfaces by the body within the request

I have created a similar structure to ASP.NET MVC and uploaded it on my github repository (express-mvc). Everything seems fine, but I am facing an issue with casting the body inside the request object to match any interface. This is what I am aiming for: ...

How to trigger a function in a separate component (Comp2) from the HTML of Comp1 using Angular 2

--- Component 1--------------- <div> <li><a href="#" (click)="getFactsCount()"> Instance 2 </a></li> However, the getFactsCount() function is located in another component. I am considering utilizing @output/emitter or some o ...

How to set return types when converting an Array to a dynamic key Object in Typescript?

Can you guide me on defining the return type for this function? function mapArrayToObjByKeys(range: [string, string], keys: { start: string; end: string }) { return { [keys.start]: range[0], [keys.end]: range[1] } } For instance: mapArrayToObj ...

What is the best way to automatically check dynamic checkboxes in Angular reactive forms based on database values?

As a beginner in reactive forms, I am facing challenges with dynamically setting the value of checkboxes to true. For instance, when retrieving pre-selected fruit values for a specific user from the database, I want those fruits to be checked when the page ...

Building Unique Password Validation with Angular 5

I'm attempting to implement custom password validation for a password field. The password must be a minimum of 8 characters and satisfy at least two of the following criteria but not necessarily all four: Contains numbers Contains lowercase letters ...

Unable to load the default value for ion-select in TypeScript

I have reviewed this question, this question, and this question. However, none of them seem to provide a straightforward solution for what I am searching for. <ion-list> <ion-item> <ion-label>Select Book</ion-label> <i ...

Choose from the Angular enum options

I am working with an enum called LogLevel that looks like this: export enum LogLevel { DEBUG = 'DEBUG', INFO = 'INFO', WARNING = 'WARNING', ERROR = 'ERROR' } My goal is to create a dropdown select el ...

Implementing Angular *ngFor to Reference an Object Using Its Key

myjson is a collection of various hijabs and headscarves: [ { "support": 2, "items": [ [ { "title": "Segitiga Wolfis", "price": 23000, "descripti ...

An error has occurred in Typescript stating that there is no overload that matches the call for AnyStyledComponent since the update to nextjs

Upgraded to the latest version of nextjs, 13.3.1, and encountered an error in the IDE related to a styled component: Received error TS2769 after the upgrade: No overload matches this call. Overload 1 of 2, '(component: AnyStyledComponent): ThemedSty ...

Extract Method Parameter Types in Typescript from a Generic Function

Can we retrieve the type of parameters of methods from a generic interface? For instance, if we have: interface Keys { create: any; ... } type MethodNames<T> = { [P in keyof Keys]: keyof T; } Then, is it feasible to obtain the type of paramete ...

Creating a dynamic CSS height for a div in Angular CLI V12 with variables

Exploring Angular development is a new venture for me, and I could use some guidance on how to achieve a variable CSS height in Angular CLI V12. Let me simplify my query by presenting it as follows: I have three boxes displayed below. Visual representatio ...

What is the best way to save emitted values from rxjs?

I'm currently grappling with understanding rxjs. In my angular project, I've created a service that emits and listens to boolean values that indicate the start and completion of asynchronous operations. export class UpdateScriptRunningEventServi ...

How can you selectively export a single function from a JavaScript file?

Within my project, I have two separate modules - one written in ts and the other in js. There is a utility within the js module that needs to be accessed by the ts module. The utility service.js looks like this: module.exports = { helloFriends: functi ...

What is the method for including word boundaries in a regex constructor?

export enum TOKENS { CLASS = 1, METHOD, FUNCTION, CONSTRUCTOR, INT, BOOLEAN, CHAR, VOID, VAR, STATIC, FIELD, LET, DO, IF, ELSE, WHILE, RETURN, TRUE, FALSE, NULL, THIS } setTokenPatterns() { let tokenString: s ...

Checking a TypeScript project with various start points for linting

Within my extensive application that is constructed using webpack, there are numerous entry points that are generated dynamically. Each entry point requires specific target files to be created during the build process. I have already realized that when bu ...

I am integrating and connecting my angular2 library with my primary project by placing it in the node_modules folder within the library's build directory. This process is expected to

I have developed an Angular2 component as a library and I am connecting this library to my main project. After building my library, a build folder is created. However, when I run npm-link inside the build folder, it generates a node_modules folder with al ...

Using [file_id] as a dynamic parameter in nextjs pages

I am working with a nextjs-ts code in the pages/[file_id].tsx file. import Head from 'next/head'; import Script from 'next/script'; import Image from 'next/image'; import Link from 'next/link'; import { NextApiReques ...

Tips for showcasing the CDK table in Angular without duplicating customer IDs

My CDK table is used to display data, but I am facing an issue with duplicated data in the dataSource as shown below: [ {customerID:"56789", name: "foo", mobile: "123456"}, {customerID:"56789", name: "foo", mobile: "123456"}, {customerID:"12345", name: "f ...

Having trouble launching my node application on port 80 on Ubuntu 16.04

Trying to run my node app on port 80 in Ubuntu 16.04 is proving to be a challenge. Despite the fact that the port is not in use, when attempting to start my app with npm start, an error message stating "Port already in use" is displayed. According to infor ...