【发布时间】:2018-11-18 10:06:57
【问题描述】:
我发现这个 Angular 的异步管道错误处理示例看起来很有希望:https://sebastian-holstein.de/post/error-handling-angular-async-pipe/
尝试在 Angular 7 中运行它会导致编译错误
readonly data$: Observable<T>;
constructor(data: Observable<T>) {
this.data$ = data.pipe(
shareReplay(1),
catchError(error => {
console.log(error);
this._errorLoading$.next(true);
return of();
})
);
}
错误:
ERROR in src/app/loading-wrapper.ts(12,5): error TS2322: Type 'Observable<{} | T>' is not assignable to type 'Observable<T>'.
Type '{} | T' is not assignable to type 'T'.
Type '{}' is not assignable to type 'T'.
全班
关于如何修复的任何建议?
【问题讨论】:
-
如何调用这个构造函数?传递给它的变量类型是什么?
-
现在在问题中添加了全班的照片。