This rule requires an explicit type annotation for error parameters in error handlers. It's similar to the TypeScript no-implicit-any-catch
rule, but is for observables - not try
/catch
statements.
Examples of incorrect code for this rule:
import { throwError } from "rxjs";
import { catchError } from "rxjs/operators";
throwError(() => new Error("Kaboom!")).pipe(
catchError((error) => console.error(error))
);
import { throwError } from "rxjs";
throwError(() => new Error("Kaboom!")).subscribe({
error: (error) => console.error(error)
});
import { throwError } from "rxjs";
import { tap } from "rxjs/operators";
throwError(() => new Error("Kaboom!")).pipe(
tap(undefined, (error) => console.error(error))
);
Examples of correct code for this rule:
import { throwError } from "rxjs";
import { catchError } from "rxjs/operators";
throwError(() => new Error("Kaboom!")).pipe(
catchError((error: unknown) => console.error(error))
);
import { throwError } from "rxjs";
throwError(() => new Error("Kaboom!")).subscribe({
error: (error: unknown) => console.error(error)
});
import { throwError } from "rxjs";
import { tap } from "rxjs/operators";
throwError(() => new Error("Kaboom!")).pipe(
tap(undefined, (error: unknown) => console.error(error))
);
This rule accepts a single option which is an object with an allowExplicitAny
property that determines whether or not the error variable can be explicitly typed as any
. By default, the use of explicit any
is forbidden.
{
"rxjs/no-implicit-any-catch": [
"error",
{ "allowExplicitAny": true }
]
}