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

Promise.catch as type of unknown when "useUnknownInCatchVariables": true #49878

Closed
gkiely opened this issue Jul 12, 2022 · 1 comment
Closed

Comments

@gkiely
Copy link

gkiely commented Jul 12, 2022

Suggestion

Currently the promise .catch argument is typed as any.
Allow setting this as unknown for greater type safety via the "useUnknownInCatchVariables" flag.

somePromise.catch(e => {
  // e: any
});

🔍 Search Terms

.catch any
Promise any unknown

✅ Viability Checklist

My suggestion meets these guidelines:

  • [ x ] This wouldn't be a breaking change in existing TypeScript/JavaScript code
  • [ x ] This wouldn't change the runtime behavior of existing JavaScript code
  • [ x ] This could be implemented without emitting different JS based on the types of the expressions
  • [ x ] This isn't a runtime feature (e.g. library functionality, non-ECMAScript syntax with JavaScript output, new syntax sugar for JS, etc.)
  • [ x ] This feature would agree with the rest of TypeScript's Design Goals.

⭐ Suggestion

See above

📃 Motivating Example

Related ticket: #6283

💻 Use Cases

Any promise based code using .catch is potentially unsafe using any.

@MartinJohns
Copy link
Contributor

Duplicate of #45602. Used search terms: catch unknown in:title

@gkiely gkiely closed this as completed Jul 12, 2022
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

2 participants