Skip to main content

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?

  1. #hash fields are enforced at runtime by the JavaScript engine, not just at compile time.
  2. Prevents accidental access from outside the class that private keyword alone cannot catch.
  3. 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.

OptionTypeDefaultDescription
ignoreFilesstring[][]File patterns to skip.
skipMethodsbooleantrueSkip 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: false to also check methods. By default, only properties are checked.
  • Already using #hash but still flagged — The rule checks for the private keyword. If the member already uses #hash notation, it is not flagged. Make sure you are not combining private with #hash.
  • Want to allow private on static methods — Use skipMethods: true (the default) to skip all method definitions, including static ones.