Note that the return type of fetch
method of HttpClient
is Promise<Response>
:
fetch(input: Request | string, init?: RequestInit): Promise<Response>;
So the catch
you are referring to comes from Promise
actually. The type definition of the catch
comes from TypeScript (lib.d.ts
) actually:
/**
* Attaches a callback for only the rejection of the Promise.
* @param onrejected The callback to execute when the Promise is rejected.
* @returns A Promise for the completion of the callback.
*/
catch<TResult = never>(onrejected?: ((reason: any) => TResult | PromiseLike<TResult>) | undefined | null): Promise<T | TResult>;
And a generic definition with any
as type for the reason
is quite justified as it covers all cases.
Hope this helps.