-
Notifications
You must be signed in to change notification settings - Fork 12.6k
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
(0,eval) produces TS2695 #12978
Comments
const myEval = eval;
myEval(`var x = 10`); I'm personally fine with TS erroring out on this. It is a really edgy case. |
Calling something hack or edge case isn't relevant. What's relevant is the usage of a given pattern. Widely-used well-known googlable "hacks" should not trigger errors. I think this check was added recently — I don't think it generated this noise in 2.0.6. It's a regression and may cause undue friction for migrating code from JS. |
@mihailik I agree there is a bar here of what we want to honor or not. |
Allowing strictly |
Totally agree with Certain type of code relies on Couple more examples: |
@yortus thanks for the providing the context. It seems a bit hand-holdy given that it's not a type level rule and that people can generally be expected to know the syntax for control flow constructs. The comma operator is definitely an easy thing to get wrong and probably something I would otherwise want to ban with a linter but not necessarily at the language level. |
Using |
Accepting PRs to allow strictly the identifier |
TypeScript Version: 2.1.4
Expected behavior:
Compile fine.
Actual behavior:
error TS2695: Left side of comma operator is unused and has no side effects.
See also at TS Playground.
(0,eval)
is a well-used convenience syntax for invokingeval
with a global scope (as opposed to the scope of the caller).One possible workaround is:
(eval||null)
. But that's longer and most of all — hard to Google the reasoning behind. Whereas(0,eval)
is easy to find a detailed explanation for.Please make it not error.
The text was updated successfully, but these errors were encountered: