-
Notifications
You must be signed in to change notification settings - Fork 12.8k
variable is declared but its value is never read when destructing array #31357
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
Well, you are clearly specifying the option const [a] = [1, 2]; |
@ShadabFaiz in this example:
And you'll notice the same error about So what I mean - it is working for functions' arguments only. For destructured array syntax it's not working. That's the problem. |
The There's no corresponding need to destructure a trailing array value, and "leading" destructure targets aren't required (i.e. If there's some reason you need to destructure the second element that we're not aware of, we can revisit, but barring that it's simply a correct error to say that this variable is unused and there isn't a reason to create a carve-out for that rule. |
Ok, it's "working as intended", but it should be intended to work in a better way (i.e. for arrays in the same way as for function, even if you have workarounds for dustructuring arrays with I've added a new issue, using a "Feature Request" template, with more explanations: #31388 This one, I think, we may close |
I think there's a pretty strong case to be made for allowing unused const [_foo, _bar, baz] = someArgsArray; They provide more obvious documentation about the structure of the array/tuple. In addition, more than a handful of bare commas can be extremely hard to follow, and error prone (especially with homogeneous arrays). |
Unused variable names |
When destructing array, I want some variables/const to be declared but explicitly make them unused. Typescript has a feature of underscoring the unused parameters for functions:
But it doesn't work for array destruction:
TypeScript Version: 3.5.0-dev.20190512
Search Terms:
Code
Expected behavior:
No error
Actual behavior:
Got an error,
'_b' is declared but its value is never read
:Playground Link:
Here's it, OR use my gist:
Related Issues:
The text was updated successfully, but these errors were encountered: