The MemoizedSelector<ICommonAppState, IMenuItemsObject[]> argument does not match the expected 'string' parameter type

I have implemented the use of createSelector from @ngrx/store in order to select an array of objects from my store.

Despite successfully compiling my application, I encountered the following error:

Argument of type 'MemoizedSelector<ICommonAppState, IMenuItemsObject[]>' is not assignable to parameter of type 'string'.

navigation.selectors.ts

import { createSelector } from '@ngrx/store';
import { REDUCER_KEY } from './navigation.constants';
import { ICommonAppState } from './../../app.state';
import { INavigationState } from './navigation.reducer';

const getStore = (state: ICommonAppState) => state[REDUCER_KEY];

export const navigationItems = createSelector(getStore, (state: INavigationState) => state.items);

navigation.component.ts

import { Store } from '@ngrx/store';
import { Observable } from 'rxjs';
import { Component, OnInit } from '@angular/core';
import { INavigationState, IMenuItemsObject } from '../store/navigation/navigation.reducer';
import { FetchNavigationItems } from './../store/navigation/navigation.actions';
import { navigationItems } from '../store/navigation/navigation.selectors';

@Component({
  selector: 'app-navigation-component',
  templateUrl: './navigation.component.html',
  styleUrls: ['./navigation.component.scss'],
})
export class NavigationComponent implements OnInit {
  public navigation$: Observable<IMenuItemsObject[]>;

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

  ngOnInit() {
    this.store.dispatch(new FetchNavigationItems());
    this.navigation$ = this.store.select(navigationItems);
  }
}

The line causing the error is:

this.navigation$ = this.store.select(navigationItems);

navigation.effects.ts

  @Effect()
  fetchNavigationItems: Observable<Action> = this.actions$
    .ofType<ActionWithPayload>(FETCH_NAVIGATION_ITEMS)
    .pipe(
      mergeMap(() => this.navigationService.get()),
      switchMap(navigation =>
        of({
          type: FETCH_NAVIGATION_ITEMS_SUCCESS,
          payload: navigation,
        })
      )
    );

Finally, here's my navigation.service.ts

import { Injectable } from '@angular/core';
import { HttpClient } from '@angular/common/http';
import { IMenuItemsObject } from '../../../store/navigation/navigation.reducer';

@Injectable()
export default class NavigationService {
  constructor(private http: HttpClient) {}

  get = () => this.http.get<INavMenuItems>('{api:navigation}');
}

export interface INavMenuItems {
  header: {
    items: IMenuItemsObject[];
  };
}

The versions being utilized are as follows:

  "@angular/animations": "^6.0.3",
    "@angular/common": "^6.0.3",
    "@angular/compiler": "^6.0.3",
    "@angular/core": "^6.0.3",
    "@angular/forms": "^6.0.3",
    "@angular/http": "^6.0.3",
    "@angular/platform-browser": "^6.0.3",
    "@angular/platform-browser-dynamic": "^6.0.3",
    "@angular/router": "^6.0.3",
    "@ngrx/effects": "^6.0.1",
    "@ngrx/store": "^6.0.1",
    "bulma": "^0.7.1",
    "core-js": "^2.5.4",
    "jwt-decode": "^2.2.0",
    "lodash": "^4.17.10",
    "rxjs": "^6.0.0",
    "zone.js": "^0.8.26"

edit The interfaces that are also being used include:

export interface IMenuItemsObject {
  key: string;
  className: string;
  type: string;
  order: number;
  showInMenu: boolean;
  showAsIcon: boolean;
  openInNewWindow: boolean;
  menuItemText?: string;
  url?: string;
  displayStyle?: string;
  children: IMenuChildren[];
}

export interface IMenuChildren {
  key: string;
  className: string;
  type: string;
  order: number;
  url: string;
  showInMenu: boolean;
  showAsIcon: boolean;
  openInNewWindow: boolean;
  displayStyle?: string;
  menuItemText?: string;
}

Answer №1

Figured it out. The issue was caused by passing the incorrect interface into the component constructor initially.

The correct syntax should have been

constructor(private dataService: DataService<ICommonData>) {}
. This is because my selector retrieves data from the common data state and then accesses the IUserData

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

Is it possible to preserve the spoken "text" through Ionic Speech Recognition for future reference?

After successfully implementing Ionic Speech Recognition in my project using the Ionic framework documentation, I am now facing a challenge with saving the text or audio input using any form input method like ngmodel or formcontrol. My attempts to bind th ...

Exploring the Way Constructors are Utilized with Decorators in TypeScript

Encountering issues when attempting to utilize constructor spreads with decorators in TypeScript, here is the code snippet: export function httpGet(path?: string, ...middlewares : Function[]) { }; Usage example: class Controller { @httpGet('/:id& ...

How can angular/typescript be used to convert a percentage value, such as 75.8%, into a number like 75.8?

I have obtained a value (for example, "75.8%") as a string from an API and I need to convert it to a number in order to apply conditions. For instance: <div class="container" [ngClass]="{ 'pos' : value > 0, ...

imported classes from a module cannot be accessed within the same module

Here is some TypeScript code that I wrote: Within my module, I am importing a library called ts-events. import {SyncEvent} from 'ts-events' module MyModule{ export class MyService{ } } In the same module but in a different file, I'm ...

What is the best way to find a match for {0} while still allowing for proper

I am working on developing a text templating system that allows for defining placeholders using {0}, similar to the functionality of .Net's string.format method. Here is an example of what I am aiming for: format("{0}", 42), // output ...

Angular | Boosting performance with asset chunking

This particular inquiry mirrors 92% chunk asset optimization - webpack. However, a satisfactory solution has yet to be found. Typically, I utilize ng serve or nmp start to initiate my service locally and it functions correctly. However, on an EC2 instance ...

Unexpected outcome in Typescript declaration file

This code snippet is dealing with the 'legend' function: legend = (value) => { return typeof value === 'boolean' ? { 'options.legend.display': value } : { 'options.l ...

Is there another option for addressing this issue - A function that does not declare a type of 'void' or 'any' must have a return value?

When using Observable to retrieve data from Http endpoints, I encountered an error message stating that "A function whose declared type is neither 'void' nor 'any' must return a value." The issue arises when I add a return statement in ...

Strategies for integrating this into an HTML template

I am currently learning Ionic 3 and I am looking to implement the select option functionality using HTML. I have already set up an ion-select component using a .ts file, but now I want to do it using HTML. The select option I have in mind is for dates, sp ...

Are you a skilled UI Designer looking to work with JHipster?

Just starting out with JHipster and I've generated my first Angular 2 project using JHipster 4.5.1. It's been an amazing journey so far! Now, I'm looking to customize the default JHipster generated Angular 2 pages and create my own custom p ...

What is the best way to implement an onChange handler for React-Select using TypeScript?

I am struggling to properly type the onchange function. I have created a handler function, but TypeScript keeps flagging a type mismatch issue. Here is my function: private handleChange(options: Array<{label: string, value: number}>) { } Typescrip ...

Displaying data from an Angular subscription in a user interface form

I am attempting to transfer these item details to a form, but I keep encountering undefined values for this.itemDetails.item1Qty, etc. My goal is to display them in the Form UI. this.wareHouseGroup = this.formBuilder.group({ id: this.formBuilder.contr ...

Creating a generic class in Typescript that can only accept two specific types is a powerful

When designing a generic class, I am faced with the requirement that a property type must be either a string or number to serve as an index. If attempting something like the code snippet below, the following error will be triggered: TS2536: Type 'T ...

Can an Angular Component be displayed using a Serverless function like Lambda on AWS?

I have a single-page application developed in JavaScript using the Angular 6 Framework, and I am interested in dynamically rendering an Angular Component that is hosted on a remote server. Currently, I am utilizing viewContainerRef to dynamically render ...

Unable to bring in a TypeScript library that was downloaded from a GitHub fork repository

Currently, I am working on developing a GitHub app using the probot library. However, I have encountered an obstacle as outlined in this particular issue. It seems that probot does not offer support for ESM modules, which are crucial for my app to function ...

What is the process of changing the name of an object's key in JavaScript/Angular?

In my possession is an established entity, this.data = { "part": "aircraft", "subid": "wing", "information.data.keyword": "test", "fuel.keyword": "lt(6)" } My objective is to scrutinize each key and if the key includes .keyword, then eliminat ...

Access information from a different component within the route hierarchy

Suppose you have three components named A, B, and C with the following routing direction: A -> B -> C To retrieve data from the previous component (going from C to get data from B), you can use the following lines of code: In Component C: private ...

A TypeScript generic function designed to accept either two arrays or two objects, but not a combination of both

Currently, I am creating an extend function in TypeScript that has the capability to: Update the first object with the keys/values of the second when given two objects. Append the elements of the second array to the first array when provided with two arr ...

Obtain data from a single module and incorporate it into a different one

In my Angular 2 application, I am dealing with two component files - home.ts and folder-selector.ts. Within the folder-selector.ts file, there is a variable named pathToNode. I am trying to figure out how to access this value from within the home.ts file ...

Sanity.io's selection of schema field types for efficient and convenient

Hey there, guys! I recently started using Sanity.io and I'm curious whether there's a way to enhance my code efficiency and reuse certain fields across different schemas. I had an idea that goes something like this: cars.ts: export default { ...