My code snippet looks like this:
portfolioList: MatTableDataSource<Portfolio>;
ngOnInit(): void {
this.backend.getStatement().subscribe(
list => {
if(list as Portfolio[])
this.portfolioList = new MatTableDataSource(list);
}
);
}
Portfolio
represents an interface.
An error message is showing:
Error: src/app/admin/statement/statement.component.ts:28:53 - error TS2345: Argument of type 'Object' is not assignable to parameter of type 'Portfolio[]'.
The 'Object' type is only compatible with a few other types. Did you mean to use the 'any' type?
Type 'Object' is missing key properties from type 'Portfolio[]': length, pop, push, concat, and more.
28 this.portfolioList = new MatTableDataSource(list);
Why is this error occurring and how can I resolve it?
I've attempted using typeof()
and instanceof
instead of as
, but haven't been successful in fixing the error.