ts-reset
ts-reset copied to clipboard
Typesafe `catch` method of `promise`
This is a feature request. Hope that catch
method can be typesafe.
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:
- https://github.com/microsoft/TypeScript/issues/45602
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
Are there any plans to address the Promise.allSettled()
concern raised in the linked upstream thread: https://github.com/microsoft/TypeScript/issues/45602#issuecomment-986496929 ?