Skip to content

+= on private property doesn't count as a read for --noUnusedLocals #25476

@DaveCousineau

Description

@DaveCousineau

TypeScript Version: 2.9.2

Search Terms:
--noUnusedLocals
+=
private property

Code
tsconfig.json:

{
   "compileOnSave": true,
   "compilerOptions": {
      "target": "es6",
      "module": "none",
      "noImplicitAny": true,
      "removeComments": false,
      "outFile": "test.js",
      "declaration": false,
      "noEmitOnError": true,
      "sourceMap": false,
      "strictNullChecks": true,
      "noUnusedLocals": true,
      "noUnusedParameters": true
   }
}

test.ts

export class TestClass {
   private mNumber: number = 0;
   private get Number(): number { return this.mNumber; }
   private set Number(value: number) { this.mNumber = value; }

   public DoSomething() {
      this.Number += 1;
   }
}

Result

c:\Temp>tsc
test.ts(3,16): error TS6133: 'Number' is declared but its value is never read.

Expected behavior:
+= should count as both a read and a write

Actual behavior:
+= seems to count as a write but not a read. though this problem doesn't occur with a public property.

Playground Link:
I don't think I can set --noUnusedLocals on the playground

Related Issues:
I found this "noUnusedLocals checks don't work with private modifier": #15775
but it was closed

Metadata

Metadata

Assignees

No one assigned

    Labels

    BugA bug in TypeScriptGood First IssueWell scoped, documented and has the green lightHelp WantedYou can do this

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions