Aller au contenu

Private member naming (ARCH3009)

Ce contenu n’est pas encore disponible dans votre langue.

Key typescript.naming.private-member-naming · Severity info · Category naming

Private/non-public members should follow the language’s privacy-signalling convention, which in TypeScript is a leading underscore. This visually separates internal state from the public API.

class Cache {
private store = new Map<string, unknown>();
private hitCount = 0;
get(key: string) {
return this.store.get(key);
}
}
class Cache {
private _store = new Map<string, unknown>();
private _hitCount = 0;
get(key: string) {
return this._store.get(key);
}
}

Prefix the private member name with a leading underscore to signal its privacy.