My goal is to create a new custom RxJS pipe operator which can handle every input like this constructor(private errorHandler: ErrorHandlerService) { const voidStream$ = of() as Observable<void>; const stringStream$ = of(''); const objectStream$ = of({ id: 1, value: 'some value' }); voidStream$.pipe(handleError(this.errorHandler, () => of(undefined))); stringStream$.pipe( handleError(this.errorHandler, () => { // do some more stuff return of(''); }) ); objectStream$.pipe(handleError(this.errorHandler, () => of(undefined))); } The main issue is how to deal with changing the return type. export function handleError<T>( errorHandler: ErrorHandlerService, innerFunction: (error: any) => Observable<T>, ): OperatorFunction<T, T> { return (source: Observable<T>): Observable<T> => { return source.pipe( catchError((error) => { errorHandler.handleError(error); return innerFunction(error); }) ); }; } Here is a Stackblitz you can play with. Continue reading...