-
-
Notifications
You must be signed in to change notification settings - Fork 2.8k
Bug: [@typescript-eslint/no-invalid-void-type] false positive on generics #7227
10000New 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
This is working as expected - though the documentation is quite unclear on this point. The option should probably be I don't remember why it was built like this specifically. @JoshuaKGoldberg this was your baby - so you remember? |
Amusingly, I think the message is mixing up argument and parameter. Today the rule allows parameters. The complaint is on arguments.
Maybe we can:
Thoughts?
...was this one of my rules? I don't remember getting too involved with it. Maybe more like a street cat I've been feeding? 😄 |
Sounds good to me! |
@JoshuaKGoldberg sorry I thought you implemented this because you love to hate But no turns out it was you, @G-Rath! typescript-eslint/packages/eslint-plugin/tests/rules/no-invalid-void-type.test.ts Lines 197 to 206 in 587ac30
|
ah crap - I should have known, past-me is always out to get me... As the original implementor though, does that mean I can arbitrarily change it? 😝 Seriously though I'll look over my original PR and try to figure out what I was thinking - I assume that I was bring over https://palantir.github.io/tslint/rules/invalid-void/ though I've not mentioned that in the PR body (but you @bradzacher mention "the original rule" in your initial review comment), and so that's probably where the logic came from rather than any strong personal opinions on my part that I've since unknowingly changed my mind about |
I've had a bit of a further look over this, and I think actually it could be argued this is a general bug maybe combined with some bad/too-generic naming because If you're not happy to just change the logic to include functions without What do folks think? |
Stumbling upon here because I also just ran into this while doing the I'd be happy with any solution that allows me to make this rule stop flagging these, but I'd add a vote for having these all controlled by a single In particular, I found it really confusing that const x = mx<void> works, but const x = mx<void>() doesn't |
If there's a PR that allows |
#7227 (comment) makes sense to me. We can treat it as a breaking change for v7 to give ourselves a bit more flexibility in option naming. Thoughts @typescript-eslint/triage-team?
No, I think that'd be too much. Much of the time |
if nobody else tackles this, i'd be happy to open a PR whatever way you want it doing this rule currently doesn't make much sense IMO because of this behaviour, and will mark many sinon calls as errors in tseslint strict config. is the tldr to add but i don't understand why anyone would ever have good reason to set that to and why |
declare function foo<T>(arg: T): string;
foo<void>(undefined); An example of why the rule bans it. A large numbe 8000 r of generics are not specifically in a return type position in functions. There's a lot that are as well though. The isssue is that we can't tell purely based on syntax - the only way to "correctly" detect would be with type info and even then things can get dubious. |
That's true. I would have probably resorted to using type info, resolving function parameters' types and checking if they resolve to only void. For the suggested solution though, If we add an option, do we want to default it to true? i.e allow void in all type parameters of call expressions? |
Brad and I chatted briefly - we're slowly starting to sour on this rule as there are a couple issues (#6547, #7227) that are surprisingly intricate with it. I also filed #8113 to track reworking the rule more holistically. I'm going to close & lock this issue for now so that we can focus on that discussion. Please do post there if you have more information to add. If it goes nowhere I'll re-open this one. Thanks all!
Great question. The proposal in #8113 is that it's always the behavior, and not an option. Let's discuss over there if there are reasons why we wouldn't want that to be the case. |
Before You File a Bug Report Please Confirm You Have Done The Following...
Playground Link
https://typescript-eslint.io/play/#ts=5.1.6&fileType=.tsx&code=CYUwxgNghgTiAEAzArgOzAFwJYHtXwFsAPAHgBUA%2BACgEoAueMgbgFgAod4kgNxy2Go1WHNhBwBzAIKpgAJRAZkMVDz4CqaUIiyoQwIe3YQF8XvwAKMHASwBnEA0vW7IVfwrwAvPF0B3eE429m7qtF4eAN7wAL4GoiZmwACyUAAODCmpJLYYMDriADSmah7efvCZ2bn5RYmCTEA&eslintrc=N4KABGBEBOCuA2BTAzpAXGUEKQAIBcBPABxQGNoBLY-AWhXkoDt8B6Jge1uYDcBDRgBNaPDpWFFS6KImjQO0SODABfECqA&tsconfig=N4KABGBEDGD2C2AHAlgGwKYCcDyiAuysAdgM6QBcYoEEkJemy0eAcgK6qoDCAFutAGsylBm3TgwAXxCSgA&tokens=false
Repro Code
ESLint Config
tsconfig
Expected Result
I expected all of these to be considered valid uses of
void
Actual Result
Only the last two uses are considered valid.
Additional Info
Maybe I'm missing something but I've read the docs a couple of times and the issues, and I can't find anything explaining why this general use of
void
is being flagged - or inversely, anything confirming that there is more logic than just "is this a generic?".Importantly the
logAndReturn
is taken from the documentation itself for showcasingWhich implies to me those patterns should not be considered warnings if
allowInGenericTypeArguments
is true. This seems to be happening from v5 onwards.The text was updated successfully, but these errors were encountered: