Skip to main content

Require Type Naming

Require type alias names in .d.ts files to start with the class name prefix derived from the file path.

Summary

The require-type-naming rule reports any type alias in a .d.ts file whose name does not start with the expected prefix. The prefix is derived from the file path after the types/ directory, with each segment converted to PascalCase.

For example, a file at types/cli/utility/changelog.d.ts produces the prefix CliUtilityChangelog. The rule only applies to .d.ts files.

Why Use This Rule?

  1. Ensures type names are predictable and can be traced back to their definition file by name alone.
  2. Prevents naming collisions by scoping every type alias to its file path.
  3. Makes imports self-documenting because the type name contains its full module context.

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.

Autofix

Autofix is not available for this rule. Flagged code must be updated manually.

Troubleshooting

  • Warning fires but the prefix looks correct — Check that the file path segments after types/ match exactly. The rule splits on / and converts each segment from kebab-case to PascalCase.
  • Rule does not fire on .ts files — This is expected. The rule only applies to files ending in .d.ts. Code files are not checked.
  • Test type files use a different prefix — Files ending in .test.d.ts have the .test portion stripped before deriving the prefix, so they use the same prefix as their non-test counterpart.