Require Hash Private
Require #hash notation for private class members instead of the private keyword.
Summary
The require-hash-private rule reports any class property or method that uses the TypeScript private keyword instead of the #hash notation for private members.
By default, methods are skipped (skipMethods: true) and only properties are checked.
Why Use This Rule?
#hashfields are enforced at runtime by the JavaScript engine, not just at compile time.- Prevents accidental access from outside the class that
privatekeyword alone cannot catch. - Keeps the codebase consistent by using one notation for all private members.
Examples
Configuration
Options
warning
ignoreFiles is an escape hatch for files where this rule genuinely does not apply. It is not intended for routine use.
| Option | Type | Default | Description |
|---|---|---|---|
ignoreFiles | string[] | [] | File patterns to skip. |
skipMethods | boolean | true | Skip method definitions from being checked. |
Autofix
Autofix is not available for this rule. Flagged code must be updated manually.
Troubleshooting
- Warning fires on a method — Set
skipMethods: falseto also check methods. By default, only properties are checked. - Already using
#hashbut still flagged — The rule checks for theprivatekeyword. If the member already uses#hashnotation, it is not flagged. Make sure you are not combiningprivatewith#hash. - Want to allow
privateon static methods — UseskipMethods: true(the default) to skip all method definitions, including static ones.