Skip to content Skip to sidebar Skip to footer

Typescript Error: Argument Of Type 'object' Is Not Assignable To Parameter Of Type '{}[]'

I'm using the Angular Material table component like so: this.userService.getUsers().subscribe((response) => { this.users = new MatTableDataSource(response); });

Solution 1:

Argument of type 'Object' is not assignable to parameter of type '{}[]'.

That does not mean that MatTableDataSource accepts the wrong parameter, but rather that your response has the wrong type. You should definetly typecast that:

  (response: {userId: number, username: string }[]) =>

or do that when passing it:

newMatTableDataSource(response as {userId: number, username: string }[])

Solution 2:

Your subscribe() function needs to pass any:

In your case (as already indicated in the comments):

this.users = newMatTableDataSource(<any> response);

In some cases it might be like this:

const myLocalData = this.getData(<any> response);

Post a Comment for "Typescript Error: Argument Of Type 'object' Is Not Assignable To Parameter Of Type '{}[]'"