GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

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 #9458

New issue
Copy link
New issue
Copy link
Closed
Closed
with --noUnusedParameters how can i skip uneeded parameters#9458
Copy link
Labels
CommittedThe team has roadmapped this issueSuggestionAn idea for TypeScript

Description

@zpdDG4gta8XKpMCd
ZpdDG4gta (zpdDG4gta8XKpMCd)
opened on Jun 30, 2016
Issue body actions

sorry 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 one
Reacted by Eugene Kulabuhov, interphx, Anton Novik, Shad Sterling and Denis Zhbankov

Activity

  1. mhegazy commented on Jun 30, 2016

    @mhegazy
    Mohamed Hegazy (mhegazy)
    on Jun 30, 2016
    Contributor
    More actions

    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
  2. Mohamed Hegazy (mhegazy)
    added
    SuggestionAn idea for TypeScript
    Needs ProposalThis issue needs a plan that clarifies the finer details of how it could be implemented.
    on Jun 30, 2016
  3. Mohamed Hegazy (mhegazy)
    changed the title [-]how can i skip uneeded parameters[/-] [+]With `--nuUnusedParameters`, how can i skip uneeded parameters[/+] on Jun 30, 2016
  4. zpdDG4gta8XKpMCd commented on Jun 30, 2016

    @zpdDG4gta8XKpMCd
    ZpdDG4gta (zpdDG4gta8XKpMCd)
    on Jun 30, 2016
    Author
    More actions

    _ works well in f#, and i like it a lot, but might be a breaking change for stuff like underscore.js

  5. RyanCavanaugh commented on Jun 30, 2016

    @RyanCavanaugh
    Ryan Cavanaugh (RyanCavanaugh)
    on Jun 30, 2016
    Member
    More actions

    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

  6. zpdDG4gta8XKpMCd commented on Jun 30, 2016

    @zpdDG4gta8XKpMCd
    ZpdDG4gta (zpdDG4gta8XKpMCd)
    on Jun 30, 2016
    Author
    More actions

    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
  7. RyanCavanaugh commented on Jul 1, 2016

    @RyanCavanaugh
    Ryan Cavanaugh (RyanCavanaugh)
    on Jul 1, 2016
    Member
    More actions

    Discussed quite a bit here https://esdiscuss.org/topic/uninteresting-parameters and I would defer to their judgement

  8. Mohamed Hegazy (mhegazy)
    removed
    Needs ProposalThis issue needs a plan that clarifies the finer details of how it could be implemented.
    on Jul 1, 2016
  9. Mohamed Hegazy (mhegazy)
    added a commit that references this issue on Jul 1, 2016

    Fix #9458: exclude parameters starting with underscore from unusedPar…

    This issue will close once commit 5de7ca2 is merged into the 'main' branch.
    5de7ca2
  10. mhegazy commented on Jul 1, 2016

    @mhegazy
    Mohamed Hegazy (mhegazy)
    on Jul 1, 2016
    Contributor
    More actions

    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
  11. mhegazy commented on Jul 1, 2016

    @mhegazy
    Mohamed Hegazy (mhegazy)
    on Jul 1, 2016
    Contributor
    More actions

    if Ryan Cavanaugh (@RyanCavanaugh) gives me a :+: i can get it in

  12. zpdDG4gta8XKpMCd commented on Jul 1, 2016

    @zpdDG4gta8XKpMCd
    ZpdDG4gta (zpdDG4gta8XKpMCd)
    on Jul 1, 2016
    Author
    More actions

    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
  13. Mohamed Hegazy (mhegazy)
    closed this as completedin #9464on Jul 1, 2016
  14. Mohamed Hegazy (mhegazy)
    added a commit that references this issue on Jul 1, 2016

    Merge pull request #9464 from Microsoft/excludeUnderscoreFromUnusedPa…

    This issue will close once commit 1d03be0 is merged into the 'main' branch.
    1d03be0
  15. Yui (yuit)
    added a commit that references this issue on Jul 18, 2016

    [Transforms] Merge master 07/11 into transform (#9697)

    This issue will close once commit 1c9df84 is merged into the 'main' branch.
    1c9df84
  16. KnisterPeter commented on Jul 21, 2016

    @KnisterPeter
    Markus Wolf (KnisterPeter)
    on Jul 21, 2016
    Contributor
    More actions

    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
  17. Ryan Cavanaugh (RyanCavanaugh)
    added
    CommittedThe team has roadmapped this issue
    on Jul 21, 2016
  18. JoshuaKGoldberg commented on Nov 10, 2016

    @JoshuaKGoldberg
    Josh Ghoulberg 👻 (JoshuaKGoldberg)
    on Nov 10, 2016
    Contributor
    More actions

    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
  19. EnverOsmanov commented on Aug 2, 2017

    @EnverOsmanov
    EnverOsmanov
    on Aug 2, 2017
    More actions

    _ 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
  20. kitsonk commented on Aug 2, 2017

    @kitsonk
    Kitson Kelly (kitsonk)
    on Aug 2, 2017
    Contributor
    More actions

    _ 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
  21. pewinski commented on Nov 14, 2017

    @pewinski
    Marcin Pewiński (pewinski)
    on Nov 14, 2017
    More actions

    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.

  22. EnverOsmanov commented on Nov 14, 2017

    @EnverOsmanov
    EnverOsmanov
    on Nov 14, 2017
    More actions

    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?

  23. pewinski commented on Nov 14, 2017

    @pewinski
    Marcin Pewiński (pewinski)
    on Nov 14, 2017
    More actions

    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
  24. RyanCavanaugh commented on Nov 14, 2017

    @RyanCavanaugh
    Ryan Cavanaugh (RyanCavanaugh)
    on Nov 14, 2017
    Member
    More actions

    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
  25. pewinski commented on Nov 14, 2017

    @pewinski
    Marcin Pewiński (pewinski)
    on Nov 14, 2017
    More actions

    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
  26. microsoft
    locked and limited conversation to collaborators on Jul 31, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    CommittedThe team has roadmapped this issueSuggestionAn idea for TypeScript

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions

      You are visitor 01402775 — GeezerVison does not store the pages you look up.
      Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.