-
Notifications
You must be signed in to change notification settings - Fork 12.8k
Report error for common no-op statements #5669
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
Comments
What if this looks like a tslinlt rule to me. |
|
I expect the vast majority of getters to have no side-effects in pratice and as such, they don't make sense as standalone expressions either (whether this is too a big assumption to make in the compiler or not, I don't know.) Thanks for the pointers to Still thinking it would be nice to prevent this kind of footgun at the language level, similarly to #2575 and the upcoming reachability analysis, but I'll defer to you. Please close if you still think it doesn't belong in the language. |
So one reason a person might use a standalone identifier as a statement expression is to ensure that we don't perform module import elision. Basically, if we never use any value entity from a module, then we assume it was only used for types. This means people end up needing to do something like import * as foo from "fooModule";
import "fooModule"; However, another reasonable way to trigger this would be import * as foo from "fooModule";
foo; So I'm going to lean on the side that this is more in the scope of linters. |
Assuming the following code:
Would it be possible for TypeScript to complain about the
doSomething;
line, notifying the user that the statement is a no-op and maybe even suggesting adding parentheses to call the function? Or do you folks consider that kind of problems to definitely be a linter error, rather than something the compiler should look out for?I searched the bugtracker but couldn't find any similar requests, my apologies if I missed them. I don't even know how feasible this would be, maybe ECMAScript has intricacies that make it impossible in all but the simplest cases, but I thought it couldn't hurt to suggest it.
The text was updated successfully, but these errors were encountered: