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

Typed the error param of Promise.catch as unknown #112

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

syhner
Copy link

@syhner syhner commented Mar 10, 2023

When using try...catch in strict mode (or with the useUnknownInCatchVariables tsconfig flag enabled) the type of error is unknown

try {} catch (error) {}
//            ^? error: unknown

However when working with promises, the type of a caught error is any

Promise.resolve().catch((error) => {});
//                       ^? error: any

This PR changes the type of error to unknown for consistency (and type safety)

Promise.resolve().catch((error) => {});
//                       ^? error: unknown

@syhner syhner changed the title Typed the error param of Promise.catch as unknown Typed the error param of Promise.catch as unknown Mar 20, 2023
@syhner syhner changed the title Typed the error param of Promise.catch as unknown Typed the error param of Promise.catch as unknown Mar 20, 2023
@syhner syhner changed the title Typed the error param of Promise.catch as unknown Typed the error param of Promise.catch as unknown Mar 20, 2023
@Raynos
Copy link

Raynos commented Aug 30, 2023

This looks great, can we have it merged /

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

Successfully merging this pull request may close these issues.

None yet

2 participants