0
我期待从2角一个应用程序升级到4,我发现了以下错误:错误的角度和RXJS承诺
Type 'Promise<void | Store>' is not assignable to type 'Promise<Store>'.
类型“无效|商店'不能分配键入'存储'。 类型'void'不可指定为'Store'类型。
有问题的线路是这样的:
return this.http.get(url, { headers: this.headers })
.toPromise()
.then(response => response.json().data as Store)
.catch((err) => { console.log('An error occurred under StoreService.StoreGetById', err); });
这个工作我升级之前,我是相当新的RxJS。
这不是一个RxJS问题;这是一个TypeScript问题。和'承诺'类型更准确地传达情况。你的“catch”会吞噬错误,并不会返回任何内容 - 因此是“void”。有两种可能的途径:一种解决为“商店”;另一个解决为“无效”。我会通过重新抛出错误来解决问题,因为吞咽它只会导致参考错误发生。 –
cartant