angularrxjsrxjs-observablesrxjs7angular14upgrade

Expected 0-1 arguments, but got 2.ts(2554) in Subscribe Error handler


we have just recently upgraded Rxjs Latest(8.0.0-alpha.5) version.And this error started appearing.

this.ReportController.ExportTableExcelBackground(model).subscribe(
            (x) => {
              this.appController.BlockApplication(false);
              if (x.IsSuccess) {
                const msgInfo = "The report will be downloaded when finished.";
                this.alertController.RegisterAlertMessage(
                  [msgInfo],
                  AlertMessageType.SUCCESS,
                  true
                );
              } else {
                this.appController.OpenErrorServerPopup(x.Message);
              }
            },
            (error: any) => {
              this.appController.BlockApplication(false);
              this.appController.OpenErrorServerPopup(error);
            }
          );

When hover on error it says Expected 0-1 arguments, but got 2 Any idea what is changed in RXJS latest version and how to fix this?


Solution

  • What line in this code show the error?

    Is it the subscribe() call? Observable.subscribe() declaration has changed since RxJS 7 and the way you're using it has been deprecated and in RxJS 8 removed. If you want to handle two notification types you'll need to use an observer object:

    source$.subscribe({
      next: () => {},
      error: e => {},
    });
    

    Just FYI Subscribe is deprecated: Use an observer instead of an error callback.