我正在阅读catchError
的源代码。我注意到它的定义如下:似乎它将一个带有两个参数并返回Observable
-selector: (err: any, caught: Observable<T>) => ObservableInput<R>
export function catchError<T>(selector: (err: any, caught: Observable<T>) => never): MonoTypeOperatorFunction<T>;
export function catchError<T, R>(selector: (err: any, caught: Observable<T>) => ObservableInput<R>): OperatorFunction<T, T | R>;
export function catchError<T, R>(selector: (err: any, caught: Observable<T>) => ObservableInput<R>): OperatorFunction<T, T | R> {
return function catchErrorOperatorFunction(source: Observable<T>): Observable<T | R> {
const operator = new CatchOperator(selector);
const caught = source.lift(operator);
return (operator.caught = caught as Observable<T>);
};
}
但是在使用catchError
的示例中,似乎采用了带有一个参数catchError(err => of[])
的函数。这些示例为什么不需要第二个参数caught
?