total-typescript / ts-reset

A 'CSS reset' for TypeScript, improving types for common JavaScript API's

Home Page:https://www.totaltypescript.com/ts-reset

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Typesafe `catch` method of `promise`

zanminkian opened this issue · comments

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

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