Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/angular/32.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Angular 类型为'的参数;{type:string;weight:number;}';不可分配给类型为';绝不';有棱角的_Angular_Typescript - Fatal编程技术网

Angular 类型为'的参数;{type:string;weight:number;}';不可分配给类型为';绝不';有棱角的

Angular 类型为'的参数;{type:string;weight:number;}';不可分配给类型为';绝不';有棱角的,angular,typescript,Angular,Typescript,我试图在我的angular material表中显示json数据,但我有一个不明白的问题 错误: 类型参数“{type:string;weight:number;}”不能分配给类型参数“never”。 类型从来就不是什么意思 ts.file export class TableComponent implements OnInit { ELEMENT_DATA: Itype[] = []; displayedColumns: string[] = ['dechets.type', 'd

我试图在我的angular material表中显示json数据,但我有一个不明白的问题

错误: 类型参数“{type:string;weight:number;}”不能分配给类型参数“never”。

类型从来就不是什么意思

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); // probleme is here
        return acc;
      }, []);
    });
  }
export interface Itype {

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

如果要从
resp
数组的每个元素中收集所有
dechets
数组并将其展平,可以使用
array#map
array#flat

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

尝试定义acc的类型:IType[]这是否回答了您的问题:?