Skip to content

Unused underscore variables not being ignored by lint rules #19614

Closed

Description

TypeScript Version: 2.7.0-dev.20171031, 2.6.1 (Regression from 2.5.3)

Expected behavior:
Variables with names that begin with an underscore do not cause an error if not used.

Actual behavior:
components/panel/panel.ts(22,11): error TS6133: '_someVariable' is declared but its value is never read.

Activity

  1. changed the title [-]Unused underscore variables note being ignored by lint rules[/-] [+]Unused underscore variables not being ignored by lint rules[/+] on Oct 31, 2017
  2. chmeyers commented on Oct 31, 2017

    @chmeyers
    Author
  3. chmeyers commented on Oct 31, 2017

    @chmeyers
    Author

    Repro:
    class TestClass {
    private _shouldBeIgnored: boolean;

    _someFunction() {
    this._shouldBeIgnored = true;
    }
    }

    tsc --noUnusedLocals test.ts
    (Works in 2.5.3, fails on 2.6.1 (and latest nightly))

  4. chmeyers commented on Oct 31, 2017

    @chmeyers
    Author

    In our particular case these variables are read by the html page.

  5. nikklassen commented on Nov 1, 2017

    @nikklassen

    My use case for this is array destructing. I have a function that returns a "tuple" (an array like [int, string]) and in some cases I would like to ignore one of the elements i.e. const [_foo, bar] = func() but keep the tuple-like semantics. const bar = func()[1] no longer communicates that this is a tuple.

  6. aluanhaddad commented on Nov 2, 2017

    @aluanhaddad
    Contributor

    Nik Klassen (@nikklassen) you can use a leading , as in

    const [ , bar ] = func();
  7. petemcwilliams commented on Nov 8, 2017

    @petemcwilliams

    This warning

    is written to but it doesn't appear to be read anywhere

    Would be more useful than the one I was getting in version 2.6.1

    is declared but its value is never read.

    Because it is a new check I was searching for quite a while to figure this out, seeing the variable was being used (written to) in the ts.

  8. typescript-bot commented on Nov 22, 2017

    @typescript-bot
    Contributor

    Automatically closing this issue for housekeeping purposes. The issue labels indicate that it is unactionable at the moment or has already been addressed.

  9. locked and limited conversation to collaborators on Jun 14, 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

    Working as IntendedThe behavior described is the intended behavior; this is not a bug

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions