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?
- Ensures type names are predictable and can be traced back to their definition file by name alone.
- Prevents naming collisions by scoping every type alias to its file path.
- 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.
| Option | Type | Default | Description |
|---|---|---|---|
ignoreFiles | string[] | [] | 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
.tsfiles — 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.tshave the.testportion stripped before deriving the prefix, so they use the same prefix as their non-test counterpart.