Type 'function that accepts an argument of type User and TypedAction<"login start"> and returns void'

I recently started learning TypeScript and I'm delving into state management in Angular 11. However, when I try to create an effect, I encounter an error stating Argument of type '(action: User & TypedAction<"login start">) => void'.

I have attempted the following code:

  login$ = createEffect(() => {
    return this.actions$.pipe(
      ofType(loginstart),

      //   Argument of type '(action: User & TypedAction<"login start">) => void' is not assignable to parameter of type '(value: User & TypedAction<"login start">, index: number) => ObservableInput<any>'.
      //   Type 'void' is not assignable to type 'ObservableInput<any>'
      exhaustMap((action) => {
        console.log(action);
      })
    );
  });

Action
const LOGIN_START = 'login start';
export const loginstart = createAction(LOGIN_START, props<User>());

export interface User {
  name: string;
  email: string;
}

How should I go about resolving this issue?

Answer №1

The reason for this issue is that you are not returning Action from Effect.

      @Effect()
  login$ = createEffect(() => {
    return this.actions$.pipe(
      ofType(loginstart),

      //   Argument of type '(action: User & TypedAction<"login start">) => void' is not assignable to parameter of type '(value: User & TypedAction<"login start">, index: number) => ObservableInput<any>'.
      //   Type 'void' is not assignable to type 'ObservableInput<any>'
      exhaustMap((action) => {
        console.log(action);
        return of(someAction)
      })
    );
  });
  constructor(private actions$: Actions) {}

You can define the returned action as needed:

export const someAction = createAction('login start success or something');

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

Creating a Typescript type that specifically accepts a React component type with a subset of Props

Imagine a scenario where there is a component called Button, which has specific props: ButtonProps = { variant: 'primary' | 'secondary' | 'tertiary'; label: string; // additional props like onChange, size etc. } Now, th ...

Encountering difficulties in running bootstrap on nodejs

As a beginner in node.js and bootstrap, I am eager to create my own personal website, so I found some tutorials to help me get started. After downloading bootstrap 2.0.2 and unzipping it, I organized the files by placing bootstrap and bootstrap-responsive ...

Tips on utilizing spin.js in client-side scripts (Javascript and Node)

I've been attempting to utilize spin.js (!) from the client side, but unfortunately I have encountered some obstacles. I tried running npm install spin.js afterwards const Spinner = require('spin.js'); However, this approach was unsu ...

Using AngularJS to convert a JSON object into an array

Hey there, I've got a JSON return object that looks like this: color_selected = [ { id: 4}, { id: 3} ]; Any tips on how I can convert it to the following format? color_selected = [4,3] Appreciate any help or s ...

Using Vue 3 to transfer data within the <slot> element

My Objective: I want to showcase an image from a dynamic link in Post.vue using the layout of PostLayout.vue Within PostLayout.vue, there is a <slot> called postFeaturedImage. Inside that slot, there is a <div> where I intend to set th ...

Legends for Jqplot Donut Chart disappearing after saving changes

I am currently working on creating a donut chart using jqplot which displays legends outside the grid. However, I have encountered an issue where when attempting to save the chart as a PNG image, the resulting image shows empty legends. var imgData = $(&a ...

Stop the setTimeout function after redirecting in the controller

I am experiencing an issue with my AJAX call as it keeps triggering my controller repeatedly. AJAX function <script type="text/javascript> var stopTime =0; var scoreCheck = function () { $.ajax({ url: "<?php echo 'http:// ...

Show a table row based on a specific condition in Angular

I'm having this issue with the tr tag in my code snippet below: <tr *ngFor="let data of list| paginate:{itemsPerPage: 10, currentPage:p} ; let i=index " *ngIf="data.status=='1'" > <td> </td> <td> ...

Naming variables in JavaScript with parentheses()

I'm currently facing some issues with my code, as it's not working properly. I have three variables that set the state of another set of three variables. Instead of writing out the code three times, I wanted to use another variable (like 'i& ...

Enable Submit Button on Click Using jQuery

I'm encountering an issue with my web page that features a submit button. The code for my submit button is shown below: <button type="submit" class="btn btn-primary wait-on-click"> <span>Submit</span> </button> Upon clickin ...

Deactivate the input fields within a dynamic form

I have already attempted to follow the solutions provided in other responses here, but unfortunately, I have not been successful! I have developed a dynamic reactive form and I am looking to disable certain fields at specific times. Below is my form code: ...

Utilizing combinedReducers will not prompt a re-render when dispatching actions

When I refrain from using combineReducers: const store = createStore<StoreState,any,any,any>(pointReducer, { points: 1, languageName: 'Points', }); function tick() { store.dispatch(gameTick()); requestAnimationFrame(tick) ...

What is the process for setting up a server-side Meteor Collection without the necessity of direct interaction?

I'm just starting out with Meteor and working on a basic recipe list. In my file (/imports/api/recipes.ts), I have defined my Recipe collection: // imports/api/recipes.ts export interface Recipe { _id?: string; title: string; createdAt: Date; } ...

Looking to create a timepicker in ReactJS similar to the Uber timepicker, with the added feature of a "Now"

https://i.sstatic.net/wxY1O.jpg {val.getDate() === +todayDate ? ( <TimePicker className="carDetailOption" value={val} onChange={(date) => setVal(date)} ...

Is there a way to combine two independent javascripts into a single script?

How can I merge two separate javascript functions into one? I have a script that sends form data to post.php without refreshing the page and also refreshes the content of a specific DIV, but I also have another script that disables the corresponding form ...

Is there a way to mark a template-driven form as invalid when a custom field validator fails in my Angular 15 application?

Currently, I am working on an Angular 15 app that utilizes a hand-coded JSON file along with the JSON server for performing CRUD operations on a "employees" JSON data. One of the tasks at hand involves adding custom validation to a <select> element. ...

While attempting to update the package.json file, I encountered an error related to the polyfills in Angular

I have been working on a project with ng2 and webpack, everything was running smoothly until I updated the package.json file. Since then, I have been encountering some errors. Can anyone please assist me in identifying the issue? Thank you for any help! P ...

Running a function of a component from within another component

In order to prevent any clutter and avoid using "native" jQuery/javascript, my goal is to elegantly call a function in the child component from the parent. The specific function I want to execute is change_map_data() from the child component G_Map.vue, all ...

Setting the text alignment using the innerHTML property of CSS

Having difficulty aligning text with innerHTML I am trying to create a link element using JavaScript, but I cannot get the text to align to the center. Here is my code: a= document.createElement('a'); a.style.cssText= 'font-size: 20px; curs ...

Comparing Redux with passing state down to components as props from the top level of the application

With limited experience in react-redux, I am currently working on a smaller web-based application intended for around 100 users. At this time, I have opted not to use redux due to concerns about its complexity for such a small project. Instead, I have been ...