Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Typesafe catch method of promise #148

Open
zanminkian opened this issue Jun 8, 2023 · 3 comments
Open

Typesafe catch method of promise #148

zanminkian opened this issue Jun 8, 2023 · 3 comments

Comments

@zanminkian
Copy link

zanminkian commented Jun 8, 2023

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

@NateRadebaugh
Copy link

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
Copy link

Looks like this will be solved by #112

@sybereal
Copy link

Are there any plans to address the Promise.allSettled() concern raised in the linked upstream thread: microsoft/TypeScript#45602 (comment) ?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants