2

I have below function which return an array-based it has two inputs one is type and second one is input array.

3
  • @DhananjaiPai updated my answer please check Commented Oct 10, 2019 at 17:12
  • 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. Commented Oct 10, 2019 at 17:14
  • @Igor can you help me in this as well stackoverflow.com/questions/58329020/… Commented Oct 10, 2019 at 18:29

1 Answer 1

2

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;  
  }
Sign up to request clarification or add additional context in comments.

1 Comment

can you help me in this as well stackoverflow.com/questions/58329020/…

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.