A private field or method is never referenced inside its class
What it finds
A private member can only be used inside its class, so when the class never mentions it, nothing does: the field, method or accessor is dead code that still has to be read and kept compiling.
Members marked private in TypeScript, members named #name, and parameter properties such as constructor(private readonly cache: Cache) are reported when no other token in the class body has their name, as a property access, a #name or a string in an element access. Decorated members, which frameworks read by reflection, are left alone, and so are declaration files, which describe classes defined elsewhere.
From the rule's source, unread_private_member.rs.
export class Store { private cache = new Map<string, number>(); private stale = 0;tx0 reports: the private member stale is never used #secret = 1;tx0 reports: the private member #secret is never used constructor(private readonly name: string, private unused: number) {}tx0 reports: the private member unused is never used get(key: string) { return this.cache.get(key) ?? this.name.length; } private helper() {tx0 reports: the private member helper is never used return 1; }} Turn it on, off or suppress it
The rule runs in every tier. To turn it off for a project, set its level in tx0.toml:
[rules]
"tx0/ts:unread-private-member" = "off"To keep one finding, suppress it with a reason. tx0 suppress ID --reason "..." writes the comment on the line before the code:
// tx0: ignore[tx0/ts:unread-private-member] reason="..."tx0 explain tx0/ts:unread-private-member shows the same in the terminal. Found a false positive? Report it.