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

Typed the error param of `Promise.catch` as `unknown`

Open syhner opened this issue 3 years ago • 1 comments

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 avatar Mar 10 '23 19:03 syhner

This looks great, can we have it merged /

Raynos avatar Aug 30 '23 21:08 Raynos