GeezerVison is showing github.com — with --noUnusedParameters how can i skip uneeded parameters · Issue #9458 · microsoft/TypeScript
with --noUnusedParameters how can i skip uneeded parameters #9458Descriptionsorry for being persistent, same question as in
#9403 (comment)
how is this going to work with unused parameters?
fiction third(x:any, y: any, z: T) : T { return z; } // need only last oneReacted by Eugene Kulabuhov, interphx, Anton Novik, Shad Sterling and Denis Zhbankov Activitymhegazy commented on Jun 30, 2016 i was thinking of _ as a special case. but that does not seem nice. the other option is to use arguments. Reacted by Javier "Ciberman" Mora, Todd Fisher, Saad Malik and Eugene Kulabuhov changed the title [-]how can i skip uneeded parameters[/-] [+]With `--nuUnusedParameters`, how can i skip uneeded parameters[/+] on Jun 30, 2016zpdDG4gta8XKpMCd commented on Jun 30, 2016 _ works well in f#, and i like it a lot, but might be a breaking change for stuff like underscore.js
RyanCavanaugh commented on Jun 30, 2016 I would propose that any local starting with _ is not subject to unused checks. For multiple parameters you could then write (_0, _1, x) => x zpdDG4gta8XKpMCd commented on Jun 30, 2016 consider third<T>(,, z: T): T { return z; } Reacted by Braden Snell, Frederick Fogerty, André Gomes, Hugh Gao, Ceyhun Can Ulker, Ville Lahdenvuo-Malta, Jacob Bogers, Hannes Früchtenicht, Kovács Vincent, Pierre Tassel and 6 more RyanCavanaugh commented on Jul 1, 2016 added a commit that references this issue on Jul 1, 2016Fix #9458: exclude parameters starting with underscore from unusedPar… This issue will close once commit 5de7ca2 is merged into the 'main' branch.5de7ca2 mhegazy commented on Jul 1, 2016 I have a fix out in #9464. any parameter name starting with _ is exempt from the check. Reacted by Frederick Fogerty, shyyko.serhiy, Ryan Smith, Nico Jansen, Jan Aagaard, David Mair Spiess, Michał Werner, Javier "Ciberman" Mora, Vedran Mandić, Chet Murphy and 13 more Reacted by Braden Snell, Elger van Boxtel, Jacob Rask and Shmavon Gazanchyan Reacted by Denis Zhbankov mhegazy commented on Jul 1, 2016 zpdDG4gta8XKpMCd commented on Jul 1, 2016 Ryan Cavanaugh (@RyanCavanaugh) the discussion you mentioned ended nowhere, but I like the point that was raised there: destructuring has been already accepting commas for unused array elements:
const values = [1,2,3];
const [,,z] = values; Reacted by Braden Snell, Shmavon Gazanchyan, Jacob Bogers, Kovács Vincent, Roly Perera, Hayato Mizuno, Ravi Mehra, Pierre Tassel, Mathieu Savy, Saad Malik and 2 more Reacted by Nima Izadi added a commit that references this issue on Jul 1, 2016This issue will close once commit 1d03be0 is merged into the 'main' branch.1d03be0 added a commit that references this issue on Jul 18, 2016This issue will close once commit 1c9df84 is merged into the 'main' branch.1c9df84 KnisterPeter commented on Jul 21, 2016 The referenced discussion is about destructuring.
I think it may introduce flaws and false positives to prefix a parameter name with _.
For example if in a current function the first parameter is not used but the second is I need to prefix the first one. If the code is refactored then and afterwards the function only has one parameter left (the first one because of api changes), then the check is disabled, because it is still prefixed.
It is very easy to forget to remove the underscore prefix.
As well we have a compiler meaning in the parameter name which I think is no good practice. If I like to skip a parameter at all, then a single underscore may be okay, but again I would think this does not lead to good readable code.
May I suggest that the compiler reduces the parameters from right to left and only the last x ones not used lead to an error?
If there are parameters on the left side of a used one, the unused error is silently ignored. Reacted by Jason Killian, Mikael Hermansson, Zev Spitz, Jasper Schulte, lowkay, Andreas Lämmlein, Josh Ghoulberg 👻, Yvo Niedrich, Marco Turi, Braden Snell and 26 more Reacted by Morris Allison III, Marcin Pewiński, Alex Walter and Doug Molineux JoshuaKGoldberg commented on Nov 10, 2016 I would add the linting argument for the variable names. It's against some coding styles to have _s in front of names. As Markus Wolf (@KnisterPeter) mentioned, we're binding compiler logic and the variable name. That feels weird.
Even worse, some coding styles prefer the _ names, and so won't benefit from the compiler flag. Reacted by Braden Snell, Louis-Dominique Dubeau, Ethan Resnick, Gustavo Gard, James Monger, AJ Richardson, Gregor, Shmavon Gazanchyan and Gabriel Harel EnverOsmanov commented on Aug 2, 2017 _ is "reserved" by underscore.js so double underscore or asterisk could be used instead
(__, __, x) => x
(*, *, x) => x
Reacted by Johan Saldes Reacted by Doug Molineux kitsonk commented on Aug 2, 2017
_ is "reserved" by underscore.js so double underscore or asterisk could be used instead
The fix, which is merged, and therefore this issue is closed states that any variable that starts with an underscore will be considered uninteresting, so a double underscore is already valid. Reacted by Shmavon Gazanchyan, Ankur Oberoi, Roman Starkov and Lucas Viñals Reacted by EnverOsmanov pewinski commented on Nov 14, 2017 I agree with Markus Wolf (@KnisterPeter) , compiler should not force developer to use particular naming convention, which might be not possible in certain cases (or may at least put other devs in confusion). I would love to see a fix for compiler, if possible. EnverOsmanov commented on Nov 14, 2017 melmoth-the-wanderer what is a problem to call unused parameters as double underscore (for example)? Can you provide an example when it is not possible? pewinski commented on Nov 14, 2017 EnverOsmanov , it's been already briefly explained above. When you change the name by appending underscore, its easy to loose the context of the change in future. Especially if _name is reserved for some kind of special cases in your team. It also might require developers to change coding styles and guidelines.
Imagine working on a long-lasting project with multiple devs involved. Years ago your team used to name private properties with _ at the beginning. And couple of month ago team decided to change coding guidelines so its not acceptable anymore in the team. So you added lint rules to warn users no to do so - and now you have a problem, because your compiler requires special naming rules! And if someone is already using double underscore for some kind of semantic information, you go and tell them what you meant by adding the third one.
In principle, it is possible to name variable starting with _ sign because JS allows that, no doubt. But I've got mixed feeling when it comes to language (compiler in this case) telling programmers how to name their variables.
For now it's just one prefix and maybe I'm overreacting, but if we start allowing such prefixes Its going to be a really messy 'language' pretty soon. Reacted by Pierre Tassel and Mike Lippert RyanCavanaugh commented on Nov 14, 2017 No one's being forced to do anything. You can turn off noUnusedParameters if this is bothersome. You can @ts-ignore if you want to silence a particular line of code. You can write your own lint rule that says ignored parameters must be named exactly _0, _1, etc..
People wanted a convenient "out" for an unused parameter in the rare cases where it was provided, and we added one that doesn't really change anything else about the language for the sake of simplicity. Reacted by Josh Ghoulberg 👻, EnverOsmanov, Mathieu Savy, brian ridley and Eugene Kulabuhov Reacted by Pierre Tassel, Eivind Hyldmo, David López Pérez, Anthony Cleaver, Kyle Palko, Doug Molineux, xcatliu and Lucas Viñals pewinski commented on Nov 14, 2017 Sure, I just share my thoughts on how to improve. I just thought it would be nice to make noUnusedParameters work out of the box without doing extra steps on dev side.
Thanks for the hint on how to deal with the problem internally, though Reacted by xcatliu and Josh
MetadataMetadataDevelopmentNo branches or pull requestsIssue actions
|