The specified argument '{ type: string; weight: number; }' cannot be assigned to the parameter of type 'never' in Angular

I'm having trouble displaying JSON data in my Angular Material table and encountering an error that I don't quite understand.

Error: What does the type 'never' mean in this context?

ts.file

export class TableComponent implements OnInit {

  ELEMENT_DATA: Itype[] = [];
  displayedColumns: string[] = ['dechets.type', 'dechets.weight'];
  dataSource = new MatTableDataSource<any>(this.ELEMENT_DATA);

  constructor(private typeService: TypeService) { }

  ngOnInit() {
    this.getAllDetails();
  }

  public getAllDetails() {
    let resp = this.typeService.getAllType();
    resp.subscribe(resp => {
      this.dataSource.data = resp.reduce((acc, item) => {
        acc.push(...item.dechets); // issue is here
        return acc;
      }, []);
    });
  }

interface

export interface Itype {

    type_collecte: string;
    dechets:
    {
        type: string;
        weight: number
    }[];
    code_traitement: string;
    annee: number;
    mois: number;
}

Answer №1

If you're interested in gathering all the arrays containing "dechets" from each element within the "resp" array and then combining them into one flattened array, you can achieve this by using Array.map along with Array.flat.

this.typeService.getAllType().subscribe(resp => {
  this.dataSource.data = resp
    .map(item => item.dechets)
    .flat(1);
});

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

Angular 2: Challenges with Utilizing Set - Limited Browser Support and Iteration Issues

I am currently developing an Angular 2 Web Application. My goal is to add users to a game by utilizing checkboxes on a screen. When a checkbox is selected, I plan to add the user to a set. mySet = new Set(); this.mySet.add(e); Once a user clicks the "Ad ...

IE11 is throwing a fit because of a pesky long-running script error caused by the powerful combination of Webpack, React,

Utilizing webpack 4.* for bundling my react 16.* and typescript 3.* project has been causing issues on internet explorer 11. I consistently encounter a "not responding long running script error" on both local and test servers (in production mode). The lac ...

The information is failing to display properly within the mat-menu

Recently, I've been working on creating a navbar that includes a submenu. Even though the navigation bar data is loading properly, I am facing some issues with the submenu functionality. As a beginner in this area, I would appreciate any help or guida ...

I'm struggling to make basic CSS work in my Next.js 13 project. I'm a beginner, can someone please help?

I am facing issues with the default CSS in my latest project. I have a file called page.modules.css and I am using classname = styles.style page.tsx import styles from'./page.module.css' export default function Home() { return ( <div cl ...

Sending data to child components in Ionic

I am currently utilizing Ionic's router-outlet to navigate between a parent page and three children pages: parent.page.html <ion-content> <ion-router-outlet></ion-router-outlet> </ion-content> parent-routing-module.page.t ...

Creating Multiple Routes in a Single TypeScript and AngularJS Route File

I have built a module with TypeScript and AngularJS that includes multiple pages. I would like to use one TypeScript controller per page. How can I define multiple controllers in my routes? Currently, I have only defined one, but what if I have 6 or 7 co ...

Steps for connecting data to a react table

This is my first time working with React and I want to display the following data (id, name, status, and quantity): interface Goods { id: number; name: string; status: string; quantity?: number; } export const getGoods = (): Promise<Goods[]> ...

Issue: The variable 'HelloWorld' has been declared but not utilized

Why am I encountering an error when using TypeScript, Composition API, and Pug templating together in Vue 3? How do I resolve this issue when importing a component with the Composition API and using it in a Pug template? ...

The Angular application's "wait" dialog fails to appear

I'm currently setting up a dialog that includes a mat-spinner while the page data is loading in an Angular v14 project. Instead of using a basic spinner, I opted for a dialog because I need to pass some additional information within it. However, I&apo ...

Customizing the HTMLElement class to modify particular attributes

Is there a way to modify the behavior of an HTMLElement's scrollTop property by adding some extra logic before updating the actual value? The common approach seems to be deleting the original property and using Object.defineProperty(): delete element. ...

Navigating using the Angular router occurs before any other lines of code are executed

I am encountering an unusual issue with my Angular code involving a login page that interacts with an API. login.component.ts: export class LoginComponent implements OnInit { formData; constructor(private usersService: UsersService, private router: ...

Guide to configuring the active Tab in Angular 6 using Angular Material Design

I've searched high and low for a solution to this issue, but I haven't been able to find one. In a particular component, I have a material tab control. However, the active tab doesn't display until I click on one of the tabs on the page. a ...

In Typescript with Vue.JS, the type 'Users[]' does not include the essential properties of type 'ArrayConstructor' such as isArray, prototype, from, of, and [Symbol.species]

Embarking on my journey with typescript and vuejs, I stumbled upon a perplexing error that has halted my progress for the past 48 hours. The error message reads as: Type 'Users[]' is missing the following properties from type 'ArrayConstruct ...

Unable to determine model dependency in Nest

I encountered an issue where Nest is unable to resolve dependencies. The error message from the logger reads as follows: [Nest] 39472 - 17.08.2023, 05:45:34 ERROR [ExceptionHandler] Nest can't resolve dependencies of the UserTransactionRepository ( ...

How can I apply concatMap in Angular?

Can you please guide me on how to effectively utilize concatMap with getPrices() and getDetails()? export class HistoricalPricesComponent implements OnInit, OnDestroy { private unsubscribe$ = new Subject < void > (); infoTitle ...

Angular: Navigating to a distinct page based on an API response

In order to determine which page to go to, based on the response from an API endpoint, I need to implement a logic. The current API response includes an integer (id) and a string (name). Example Response: int: id name: string After making the API call, I ...

Electron triggers MouseLeave event on child elements

Dealing with mouse hover events can be a bit tricky, especially when working with AngularJS in an Electron-hosted app. Here's the HTML template and script I'm using: HTML: <div id="controlArea" (mouseenter) = "onControlAreaEnter()" ...

What is the best access modifier to use for TypeScript properties and functions in Angular 2 that will be accessed in the view?

Which access modifier is recommended for ng2 properties and methods that should only be used from the view? I usually use private, but came across this post advising against it: Angular2 - should private variables be accessible in the template? However, ...

looking to showcase the highest 'levelNumber' of elements within an array

arr1 = [ { "levelNumber": "2", "name": "abc", }, { "levelNumber": "3", "name": "abc" }, { "levelNumber": "3", "name": &quo ...

Tips for integrating a custom handler to the close icon in Material UI TextField component

In my Reactjs/Typescript project using Material UI, I have a search input component rendered with TextField. The built-in "x" icon clears the input value, but I want to create a custom handler for making an API call when the search value is deleted. I&apo ...