After updating Angular from version 4 to 9, I have encountered some errors that I am struggling to resolve.
Here is a snippet of my code:
this.getTrades().then((trades) => {
console.log(trades);
this.trades = new MatTableDataSource<Trade>(trades);
});
getTrades() {
let promise = new Promise((resolve, reject) => {
this.dataService.getTrades().subscribe((trades) => {
resolve(trades);
});
});
return promise;
}
export interface Trade {
ID: number;
UserID: number;
DateTime: Date;
Exchange: Exchange;
BaseCoin: Coin;
MarketCoin: MarketCoin;
Price: number;
Amount: number;
Total: number;
Last: number;
Type: Type;
Status: Status;
Symbol: string;
}
The function getTrades()
uses the following data source:
getTrades() {
return this.http.get('http://localhost:8888/currencytracker-api/json/get-trades.php').pipe(
map(res => res.json()));
}
It retrieves a JSON array with the specified data fields.
This is the error message I am encountering:
ERROR in src/app/components/trades/trades.component.ts:100:68 - error TS2345: Argument of type 'unknown' is not assignable to parameter of type 'Trade[]'. Type '{}' is missing the following properties from type 'Trade[]': length, pop, push, concat, and 26 more.
this.trades = new MatTableDataSource(trades);
If anyone can help me understand this error and how to fix it, I would greatly appreciate it. Thank you.
Update:
I initially declared the trades variable as:
Trade[]
However, I have now declared it as:
MatTableDataSource<Trade>