Typesafe `catch` method of `promise`
zanminkian opened this issue · comments
I know there is a useUnknownInCatchVariables
in tsconfig.json
but it doesn't seem to work for promises.
There's a similar request in the TypeScript codebase, but that feature request hasn't gotten any traction:
It's suggested that something like this could solve the issue but I haven't been able to get that working myself:
// Promise.d.ts
interface Promise<T> {
/**
* 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: unknown) => TResult | PromiseLike<TResult>) | undefined | null,
): Promise<T | TResult>;
}
Looks like this will be solved by #112