SonarQube 显示 "Remove this unnecessary cast"

SonarQube displaying "Remove this unnecessary cast"

为什么 SonarQube 会出现此错误,我该如何解决?

Remove this unnecessary cast.

Promise.all([
  this.customerViewCmr4tProvider.getData(activeNumber),
  this.customerBillManagementProvider.getData(individualPublicId, billingAccountId, false),
  this.agreementProvider.getData(this.activeCustomerServiceProvider.getPhoneNumber(), this.activeCustomerServiceProvider.getCmsProfile()
  )]
)
  .then(
    (results) => {
      let customerViewRootCrm4tModel = new CustomerViewRootCrm4tModel();
      let customerBillModel = new CustomerBillRootModel();
      let agreementRoot = new AgreementRoot();

      if (results[0] instanceof CustomerViewRootCrm4tModel) {
        customerViewRootCrm4tModel = results[0] as CustomerViewRootCrm4tModel;
      }

      if (results[1] instanceof CustomerBillRootModel) {
        customerBillModel = results[1] as CustomerBillRootModel;
      }

      if (results[2] instanceof AgreementRoot) {
        agreementRoot = results[2] as AgreementRoot;
      }

      const numberDevices = this.customerViewCmr4tProvider.getProductByActiveNumber(customerViewRootCrm4tModel, activeNumber).length;
      const lastBill = this.customerBillManagementProvider.getLastCustomerBill(customerBillModel).amountDue.value;
      const agreement = this.getAgreementMonthsLeft(agreementRoot);
      this.sendGoogleAnalyticsPageView(numberDevices.toString(), agreement, lastBill);
    },
    () => {
      // error
      this.sendGoogleAnalyticsPageView("", "", null);
    }
  );

在任何提供类似错误的语言中,Java、C# 等等,该消息仅表示您正在转换的变量类型已经是您尝试将其转换为的类型。他们只是告诉您删除演员表,这样就可以:

customerViewRootCrm4tModel = results[0] as CustomerViewRootCrm4tModel;

你应该这样做:

customerViewRootCrm4tModel = results[0];