I have below function which return an array-based it has two inputs one is type and second one is input array.
1 Answer
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;
}
1 Comment
Passionate Coder
can you help me in this as well stackoverflow.com/questions/58329020/…
IAssetClassorICurrencyso you can't assume that an instance will have fieldassetClassavailable.