import { EMPTY, Observable, of } from "rxjs";
import { catchError, switchMap, tap } from "rxjs/operators";

function ofType<T>(type: string, ...moreTypes: string[]): (source: Observable<T>) => Observable<T> {
    return source => source;
}

type Actions = Observable<any>;
const actions = of({});
const that = { actions };

const safePipedOfTypeEffect = actions.pipe(
    ofType("DO_SOMETHING"),
    tap(() => {}),
    switchMap(() => EMPTY.pipe(catchError(() => EMPTY)))
);
const unsafePipedOfTypeEffect = actions.pipe(
    ofType("DO_SOMETHING"),
    tap(() => {}),
    switchMap(() => EMPTY),
    catchError(() => EMPTY)
    ~~~~~~~~~~                                                      [no-unsafe-catch]
);

const safePipedOfTypeEffect = that.actions.pipe(
    ofType("DO_SOMETHING"),
    tap(() => {}),
    switchMap(() => EMPTY.pipe(catchError(() => EMPTY)))
);
const unsafePipedOfTypeEffect = that.actions.pipe(
    ofType("DO_SOMETHING"),
    tap(() => {}),
    switchMap(() => EMPTY),
    catchError(() => EMPTY)
    ~~~~~~~~~~                                                      [no-unsafe-catch]
);

const safePipedOfTypeEpic = (action$: Actions) => action$.pipe(
    ofType("DO_SOMETHING"),
    tap(() => {}),
    switchMap(() => EMPTY.pipe(catchError(() => EMPTY)))
);
const unsafePipedOfTypeEpic = (action$: Actions) => action$.pipe(
    ofType("DO_SOMETHING"),
    tap(() => {}),
    switchMap(() => EMPTY),
    catchError(() => EMPTY)
    ~~~~~~~~~~                                                      [no-unsafe-catch]
);

[no-unsafe-catch]: Unsafe catch usage in effects and epics is forbidden
