total-typescript / ts-reset

A 'CSS reset' for TypeScript, improving types for common JavaScript API's
https://www.totaltypescript.com/ts-reset
MIT License
7.74k stars 117 forks source link

Typesafe `catch` method of `promise` #148

Open zanminkian opened 1 year ago

zanminkian commented 1 year ago

This is a feature request. Hope that catch method can be typesafe.

image
NateRadebaugh commented 1 year ago

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>;
}
NateRadebaugh commented 1 year ago

Looks like this will be solved by #112

sybereal commented 2 months ago

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 ?