Skip to content

Private members used only via [] notation trigger --noUnusedLocals error #14137

Description

@studds

TypeScript Version: 2.1.1 / nightly (2.2.0-dev.201xxxxx)

Version 2.1.6

Code

class PhoneBook {
   private sally: number = 123; // error TS6133: 'sally' is declared but never used.
   private sam: number =456; // error TS6133: 'sam' is declared but never used.
   getNumber(who: 'sally' | 'wendy'): number {
       return this[who]; // tsc is able to correctly deduce that this is a number
   }
}
const phoneBook = new PhoneBook();
console.log(phoneBook.getNumber('sally'));

Expected behavior:

Using a private member via [] notation should not trigger --noUnusedLocals errors.

Actual behavior:

A private member used only via [] triggers --noUnusedLocals errors.

Activity

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

    BugA bug in TypeScriptEffort: ModerateRequires experience with the TypeScript codebase, but feasible. Harder than "Effort: Casual".Help WantedYou can do this

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions