Join GitHub today
GitHub is home to over 40 million developers working together to host and review code, manage projects, and build software together.
Sign upAllow unused vars in object destructuring with rest property #556
Comments
This comment has been minimized.
This comment has been minimized.
|
Which is the two you don't want? You can just do like this and it will only extract those variables. const { a, b } = obj |
This comment has been minimized.
This comment has been minimized.
|
I need |
This comment has been minimized.
This comment has been minimized.
|
@LinusU I think @khankuan is asking about about blacklisting certain object keys and keeping the rest. In many cases, you may not know exactly which key/vals you want, as the object may contain many different pairs, but you definitely know what you don't want. Hopefully this lame contrived example demonstrates: function getUserDataToDisplay () {
const { secretKey, ...userData } = fetchFromDatabase()
return userData
}My solution would be that this is attempting to be too clever and the intent is not made clear. Rather, something like this would be better: function getUserDataToDisplay () {
// magic function blackList is defined somewhere...
return blackList(fetchFromDatabase(), 'secretKey')
}as this clearly communicates the intent to future readers (even yourself) of the code. |
This comment has been minimized.
This comment has been minimized.
https://github.com/dcousens/blacklist, may or may not fit the syntax you want |
dcousens
added
the
question
label
Jun 30, 2016
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
|
How about:
That's how it'd be done on elixir, don't know if standard allows it though! On Thu, Jun 30, 2016, 11:59 PM Rob Szewczyk notifications@github.com
|
This comment has been minimized.
This comment has been minimized.
rszewczyk
commented
Jun 30, 2016
|
I tried that at first (almost posted that exact example), but that actually binds the value of |
This comment has been minimized.
This comment has been minimized.
simonkberg
commented
Jul 4, 2016
|
Relevant discussion with usage examples: Hacker0x01/react-datepicker#517 (comment) |
This comment has been minimized.
This comment has been minimized.
|
What if we update const { secret: _, ...data } = foo |
This comment has been minimized.
This comment has been minimized.
|
Scratch that -- that wouldn't work for ignoring two keys: const { secret: _, secret2: _, ...data } = fooLet's just wait for ESLint to add first-class support for this. This is an experimental language feature anyway. Blocked on: eslint/eslint#4880 |
feross
changed the title
Unused Variables for filtering keys
Allow unused vars in object destructuring with rest property
Jul 13, 2016
feross
added
blocked
enhancement
and removed
question
labels
Jul 13, 2016
This comment has been minimized.
This comment has been minimized.
qzb
commented
Jul 19, 2016
|
@feross Why experimental? It's part of current standard and it's supported by current versions of node.js, chrome, firefox and even egde |
This comment has been minimized.
This comment has been minimized.
simonkberg
commented
Jul 19, 2016
|
@QZD we're talking about the "Rest/Spread Properties" proposal which is currently in stage 2 https://github.com/tc39/proposals |
This comment has been minimized.
This comment has been minimized.
qzb
commented
Jul 19, 2016
|
@simonkberg @feross Sorry, my bad. |
This comment has been minimized.
This comment has been minimized.
|
Trying to clean up the open issues on this repo. This issue should be reevaluated when Rest/Spread Properties becomes part of the official language standard and ESLint adds a rule to support this usage. I would keep an eye on eslint/eslint#4880 to see if there's a new issue/PR posted that implements this functionality. |
khankuan commentedJun 29, 2016
Hi, I've a question for the following syntax:
This is useful to filter out certain keys in an obj. However, it does create 2 unused variables. Wanted to know the alternative that others might use.
Cheers :)