-
Notifications
You must be signed in to change notification settings - Fork 12.8k
noUnusedLocals doesn't error when using a ...rest declaration #61748
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
This is working as intended. It's indirectly used by removing the variable from the rest. If you remove it, you will get different behavior (it's suddenly part of the rest again). |
Hmm yes but the variable itself is unused and I expected an error there.. I can always rename it with an underscore prefix to avoid putting it back in the rest. Iβve since enabled the typescript-eslint version of this rule which lets me error for this so Iβm unblocked personally but this seems pretty unexpected |
Completely expected to me. :-) And intentional, see #12778. Having to write |
Yes but forgetting to use a variable you intended to use is a correctness bummer which bothers me more than typing a few more characters. The linked issue seems to assume that destructured properties with a rest sibling are only intended to remove properties from the rest element but in my experience thatβs actually the less common intention. Usually, I intend to use both the destructured properties and the rest element. I can see how this is convenient when your intention is to use destructuring as a poor manβs omit but I would argue that using an actual omit utility would be more clear for that whereas itβs more clear and expected to use all local declarations. Regardless as I said Iβm unblocked but I do feel strongly that trading correctness for convenience is a poor trade off. |
Having an unused variable is not a lapse in correctness, and warnings or errors for such situations are closer to lints than true compiler errors. Given that, exactly what to error on is more of a judgment call and convenience is important. |
It is inconsistent and would have confused me just the same to discover that |
π Search Terms
desctructure noUnusedLocals rest
π Version & Regression Information
β― Playground Link
https://www.typescriptlang.org/play/?noUncheckedIndexedAccess=true&noUnusedLocals=true&noUnusedParameters=true&target=99#code/GYVwdgxgLglg9mABAWznAFASkQbwFCKGIQIDOUiAhogLy7UBciAjADSIBGiTATAL4EiJMOVyd2AOikAnAKai+tKgG5BhNcTIUIS5qoFA
π» Code
π Actual behavior
no error on an unused local
π Expected behavior
error on any unused local whether a ...rest param is used or not
Additional information about the issue
No response
The text was updated successfully, but these errors were encountered: