I have below function which return an array-based it has two inputs one is type and second one is input array.
I have below function which return an array-based it has two inputs one is type and second one is input array.
You need to assert the type before you start calling properties. The pipe means the instance can implement IAssetClass or ICurrency so you can't assume that an instance will have field assetClass available.
getChartData(type : Type, data : (IAssetClass | ICurrency)[]) : IChartClass[] {
let returnArr = [];
if (type === 0) {
returnArr = data.map(
(row:IAssetClass) => ({ 'name': row.assetClass, 'weighting': row.weighting }),
)
} else {
returnArr = data.map(
(row:ICurrency) => ({ 'name': row.riskCurrency, 'weighting': row.weighting }),
)
}
return returnArr;
}