ts-reset icon indicating copy to clipboard operation
ts-reset copied to clipboard

Typesafe `catch` method of `promise`

Open zanminkian opened this issue 1 year ago • 3 comments

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

zanminkian avatar Jun 08 '23 07:06 zanminkian

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>;
}

NateRadebaugh avatar Jun 30 '23 14:06 NateRadebaugh

Looks like this will be solved by #112

NateRadebaugh avatar Jul 13 '23 01:07 NateRadebaugh

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 ?

sybereal avatar May 23 '24 15:05 sybereal