将数据源设置为新的 MatTable 数据源 Angular 7

Setting datasource to new MatTable Data Source Angular 7

当我将我的数据源设置为一个数组并尝试将 dataSource 设置为一个新垫子 table dataSource 以便能够使用它附带的过滤时,我得到了错误:

Type 'MatTableDataSource' is missing the following properties from type 'TableRecord[]': length, pop, push, concat, and 24 more.

但是,如果我将数据源设置为任何,它就可以正常工作。有人可以帮我理解为什么吗:

service.ts

export interface PaginatedListResponse<TableRecord>{
  length: number,
  tableRows: Array<TableRecord>
}

export interface TableRecord{
  x: string,
  y: string,
  z: boolean,

}

.ts

dataSource: TableRecord[] = [];
this.dataSource = new MatTableDataSource(response.tableRows);
//errror: Type 'MatTableDataSource<TableRecord>' is missing the following properties from type 'TableRecord[]': length, pop, push, concat, and 24 more.

工作示例

    dataSource: any;
    this.dataSource = new MatTableDataSource(response.tableRows);
   //No error

数据源声明错误。这样做:

dataSource: MatTableDataSource<TableRecord> = new MatTableDataSource([]) ;

然后,当您从后端接收数据时:

   this.dataSource.data = response.tableRows;