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

Enable no-throw-literal #2119

Open
ShadowJonathan opened this issue Jan 23, 2022 · 2 comments
Open

Enable no-throw-literal #2119

ShadowJonathan opened this issue Jan 23, 2022 · 2 comments

Comments

@ShadowJonathan
Copy link
Contributor

ShadowJonathan commented Jan 23, 2022

https://typescript-eslint.io/rules/no-throw-literal

A lot of code seems to depend on the fact that any thrown error is at least some form of Error, so this'd help remove the possibility for undefined bugs.

We'll probably also want to add the option "allowThrowingAny": false

@turt2live
Copy link
Member

Why?

@ShadowJonathan
Copy link
Contributor Author

As described in #2116 (comment) (at the bottom, header useUnknownInCatchVariables), handling thrown values in catch requires to treat it as anything unknown, this is because anything can be thrown, and this lint helps present this.

I think, in a large library such as this, throwing a literal value is an antipattern, as the library works and deals with Errors anywhere, having a lint which prevents developers throwing any literal value would help conform error-throwing to Errors (mostly) only, and no singleton nonsensical or context-less values such as strings, numbers, undefineds, and nulls.


This lint also has options to disallow throwing any or unknown, as these could be non-object values.

Reasons explaining why any should be prohibited anywhere is outlined in #2115, while unknown should very likely still be allowed, as with useUnknownInCatchVariables, re-throwing is also common, and with that linter, es in catch(e)s would be unknown.

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