Skip to content

unused-private ​

A private or # member of a class that nothing in the class uses, a private field written and never read, and a private member used only by other private members that are themselves unused. Idiomatic (on with "idiomatic": true), a warning. A private member is used only inside its class, so one file says it all: reported in the editor and by safe-ts check alike.

Why: a class an agent changed keeps the members the old version needed: the cache nobody reads, the helper the rewritten method stopped calling. They compile, and the next reader takes them for part of the design. TypeScript reports them only with noUnusedLocals, which strict doesn't turn on. oxlint's no-unused-private-class-members sees # members only, and not one read only by an unused method. Both spellings are reported here, fields, accessors and methods, static ones too (static #count, private static spare).

✅ Accepted: every private member is read by code that runs

✓ Accepted0 diagnostics
ts
export class Counter {
  private count = 0;
  constructor(private readonly start: number) {}
  bump(): number {
    this.count += 1;
    return this.count + this.start;
  }
}

❌ Rejected: a field written and never read, a helper nobody calls, and the field only it read

✕ Rejectedunused-private
ts
export class Counter {
  private count = 0;
  private last = 0;
  private label = "counter";
  bump(): number {
    this.count += 1;
    this.last = this.count;
    return this.count;
  }
  private describe(): string {
    return `${this.label}: ${this.count}`;
  }
}

last is written but never read; describe is never called; label is read only by describe. Delete them; if something should read them, that code is missing. The quick fix deletes a member nothing uses at all (not one that is written: the writes go with it).

Not reported: a member with a decorator (a framework reads it), a class with one, members read by obj["name"] in the same file (TypeScript allows that for private), and fields when the class reads this whole ({ ...this }, Object.keys(this), JSON.stringify(this)). A # member nothing uses is also oxlint's no-unused-private-class-members (default correctness category): a project running both sees it twice.

What it can't see ​

  • obj["name"] in another file: TypeScript lets a test read a private member that way. A member only such a test reads is reported.
  • protected and public members: a subclass or another file may use them, which is unused-code's question for whole declarations, and not asked of members.
  • A field read through a computed key (this[key]) where key isn't a literal.

MIT OR Apache-2.0 · Docs by Gemini 4 Neon Extra