The MemoizedSelector cannot be assigned to a parameter of type 'string'

Currently, my setup involves Angular 6 and NgRX 6.

The reducer implementation I have resembles the following -

export interface IFlexBenefitTemplateState {
  original: IFlexBenefitTemplate;
  changes: IFlexBenefitTemplate;
  count: number;
  loading: boolean;
}

export const INITIAL_STATE: IFlexBenefitTemplateState = {
  original: null,
  changes: null,
  count: 0,
  loading: true,
};

export default (state = INITIAL_STATE, { type, payload }) => {
  switch (type) {

    case STAGE_TEMPLATE_CHANGE:
      const pendingChanges = Object.assign({}, state.changes.sections);
      const newSection = Object.assign({}, pendingChanges[payload.key], payload, {
        changeType: 'updated',
      });

      return {
        ...state,
        changes: {
          sections: Object.assign({}, pendingChanges, { [payload.key]: { ...newSection } }),
        },
        count: !pendingChanges[payload.key].hasOwnProperty('changeType') ? state.count + 1 : state.count,
      };

    default:
      return state;
  }
};

I am using a selector to retrieve state.count, defined as shown below -

export const changesCount = createSelector(getStore, (state: IFlexBenefitTemplateState) => state.count);

In my template, I'm trying to display this value using the following approach -

@Component({
  selector: 'app-page-header-component',
  templateUrl: './page-header.component.html',
})
export class PageHeaderComponent implements OnInit {
  public count$: Observable<number>;

  public language: string;

  constructor(private store: Store<ICommonAppState>) {}

  ngOnInit(): void {
    this.count$ = this.store.select(changesCount);
    this.language = 'English';
  }
}

However, this.count$ is resulting in an error message:

[ts] Argument of type 'MemoizedSelector<IBenefitsState, number>' is not assignable to parameter of type 'string'.

I'm struggling to comprehend why this issue is occurring. Can anyone provide insight into what might be causing it?

Answer №1

Make sure to verify that you are correctly passing the appropriate interface into your store injection.

Is IFlexBenefitTemplateState present within ICommonAppState?

Answer №2

I encountered a similar issue where I thought the problem lied in having the incorrect interface within my store. Upon further investigation, I realized that it was actually due to using the wrong selector.

Big thanks goes out to @nodediggity for pointing me in the right direction!

Answer №3

I encountered a similar issue myself. The error only seemed to surface when working with angular in strict mode.

Source:

When utilizing strict mode, the select method anticipates being provided with a selector that selects from an object.
This behavior is the default of createFeatureSelector when only one generic argument is provided

Simply using the createFeatureSelector with a single generic argument resolved the problem

export const selectFeature = createFeatureSelector<FeatureState>(featureKey);

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

Navigating an angular collection like a pro

I have the following example data structure within a Component: const Questions = { "java": [ {text: "Is this a question?", answer: "Yes"}, {text: "Another question", answer: "Yes"} ], "python": [ {text: "A different qu ...

The @Input decorator in Angular 2/4 is designed to only transfer fundamental values and not collections or complex data

I have encountered an issue while attempting to use @Input with a list of objects, where the @Input variable ends up being undefined. What is functioning properly can be seen in home.component.html: <p> <it-easy [mycount]="countItem" (result ...

Angular: Issue with subscribed variable visibility on screen

I am currently developing user management functionality. When a button is clicked, the goal is to save a new user and display an incoming password stored in the system. Below is a snippet of my code: onClick() { /*Code to populate the newUser variable from ...

What is the procedure for transferring the inputted data from an HTML file to its corresponding TS file and subsequently to a different component file?

I have created two components, a login and a home-page. I am attempting to capture user input from the login template, pass it to the login component, and then display it on the home-page template using the home-page component. What is the best approach to ...

Ways to showcase alerts on dashboard

I have a specific need to incorporate a notification bell icon in my dashboard. Essentially, I want the user to be alerted about any actions that they need to take through this notification system. For example, if a task is rejected, approved, or pending v ...

Encountering a problem when parsing a JSON file in Angular 2

When attempting to access the config.json file in my Angular2 service, I have encountered an issue. load() { return new Promise((resolve, reject) => { this.http.get('./config.json') .map(res => res.json()) ...

Leveraging NestJs Libraries within Your Nx Monorepo Main Application

I am currently part of a collaborative Nx monorepo workspace. The setup of the workspace looks something like this: https://i.stack.imgur.com/zenPw.png Within the structure, the api functions as a NestJS application while the data-access-scripts-execute ...

Utilize Angular 9 with an M1 Mac device

Struggling to get my project, which utilizes Node 12 and Angular 9, up and running on my new M1 Mac. I used nvm to install node and the latest npm version, then ran the command npm i -g @angular/cli@9 to install angular. Even though which ng confirms that ...

Developing multi-layered business solutions with Angular front-end that incorporate customized localization in .Net Core Entity MVC is essential for ensuring effective business logic implementation

Help me enhance and refine this code I faced challenges trying to understand and piece together this code (coding isn't my strong suit). Sharing knowledge is important, as encouraged by platforms like StackOverflow. Please help me improve and correct ...

Utilizing Dual Destructuring for Handling Undefined Main Objects

Before we proceed, I want to clarify that my question is not a duplicate of ES6 double destructure Let's examine the code snippet related to Apollo Client GraphQL: import { gql, useQuery, useMutation } from '@apollo/client'; ... const { loa ...

When is the right time to develop a Node.js application using Typescript with dockerization

Currently, I am developing a full stack TypeScript application using Express for the server and React for the client. The folder structure of my project is organized as shown below: . ├──client/ <-- React app ├──server/ <-- Express serve ...

In TypeScript, leveraging the spread operator to determine the largest value in an array containing nullable numbers

Having an array of nullable numbers presented in the following way: let myArray : Array<number | null> = [1,2,null,4,null,5]; let maximumOfMyArray = Math.max(...myArray); // Type null is not assignable to type number I am content with JavaScript tre ...

What improvements can I make to enhance my method?

I have a block of code that I'm looking to clean up and streamline for better efficiency. My main goal is to remove the multiple return statements within the method. Any suggestions on how I might refactor this code? Are there any design patterns th ...

Does Typescript extend Node.js capabilities?

I am currently developing an application using Typescript and came across some sample Node.js code online. Can I directly use the Node.js code in my Typescript application? Essentially, I am wondering if Typescript is encompassed within Node.js. A simila ...

Combine Two Values within Model for Dropdown Menu

I am currently facing a situation where I have a select box that displays a list of users fetched from the backend. The select box is currently linked to the name property of my ng model. However, each user object in the list also contains an email proper ...

TSLint is unable to locate a custom module containing a custom d.ts file

I've been searching for a solution to this issue, but haven't found a definitive answer yet. My current challenge involves using the suncalc module with TypeScript. Since it doesn't come with its own typing file, I created one and saved it ...

What is the proper way to define the type for a functional React component by using object destructuring on props?

As I continue to learn TypeScript and work on declaring advanced types, I am faced with converting my CRA project to TypeScript. Within this project, I have a component that closely resembles examples from react-router-dom, but I have not come across any T ...

Having trouble organizing a list of objects based on changing keys

Below is the implementation of a custom pipe designed to sort records: import { Pipe, PipeTransform } from '@angular/core'; @Pipe({ name: 'sortpipe' }) export class SortPipe implements PipeTransform { transfor ...

Why is my Angular Reactive form not retrieving the value from a hidden field?

I've encountered a problem where the hidden field in my form is not capturing the product id unless I manually type or change its value. It consistently shows as "none" when submitting the form. TS https://i.stack.imgur.com/W9aIm.png HTML https://i. ...

The _rfs.scss width rule in Angular-Bootstrap-NgBootstrap is overriding the column width of the col-rules

The Dilemma I am currently working on an Angular project that incorporates Bootstrap and ng-bootstrap. My intention is to utilize the grid system within this project, but I encountered some bugs along the way. When trying to render the following HTML/TS ...