RxJS 8.0.0-alpha.5升级后subscribe报参数数量不符错误
问题描述
将RxJS升级至8.0.0-alpha.5后,出现TypeScript错误:Expected 0-1 arguments, but got 2.ts(2554),错误出现在subscribe的错误处理逻辑中。相关代码如下:
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); } );
鼠标悬停错误处提示“Expected 0-1 arguments, but got 2”,需了解该版本的变更及修复方法。
RxJS 8.0.0-alpha.5 关键变更
subscribe方法参数格式调整:不再支持将next、error、complete回调作为多个独立参数传入,仅接受单个参数。该参数可选类型为:- 单独的
next回调函数; - 包含
next、error、complete属性的观察者对象。
- 单独的
修复方案
将原有的两个回调函数封装为一个观察者对象传入subscribe即可,修改后的代码如下:
this.ReportController.ExportTableExcelBackground(model).subscribe({ next: (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: (error: any) => { this.appController.BlockApplication(false); this.appController.OpenErrorServerPopup(error); } });
内容的提问来源于stack exchange,提问作者ammad khan
相关产品推荐
相关产品推荐

