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 by PascalCasing each path segment and joining them with underscores.
For example, a file at types/cli/utility/changelog.d.ts produces the prefix Cli_Utility_Changelog. The rule only applies to .d.ts files.
A separate invalidIdentifierPrefix diagnostic fires when the first path segment starts with a digit (for example, types/2-utils/foo.d.ts), because the resulting prefix would not be a valid TypeScript identifier. Rename the directory to start with a letter so the prefix can be derived.
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 names to skip. Supports a leading-* suffix (*.test.ts), an exact path, or a trailing path segment; ** globs are not supported. |
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/, PascalCases each segment (kebab-case parts collapse together, e.g.,my-utilitybecomesMyUtility), and joins the segments with underscores. For a path segment that is already PascalCase (e.g.,MDXComponents), each internal word is re-cased to first-letter-upper, rest-lower, so all-caps abbreviations are normalized:MDXComponentsproducesMdxComponents, notMDXComponents. - Rule does not fire on
.tsfiles — This is expected. The rule only applies to files ending in.d.ts. Code files are not checked. - Rule does not fire on a
.d.tsfile outside atypes/directory — This is expected. The prefix is derived only from path segments after a/types/directory; if the file path contains no/types/segment, no prefix can be derived and the file is not checked. index.d.tsfiles use the directory prefix — A path segment namedindexis dropped when deriving the prefix, sotypes/cli/utility/index.d.tsexpects the prefixCli_Utility(the same as the directory), notCli_Utility_Index.- 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. invalidIdentifierPrefixreported on the file itself — The first path segment aftertypes/begins with a digit, so the derived prefix would not be a legal TypeScript identifier. Rename the directory to start with a letter and the rule will resume normal prefix enforcement.
Migration in 0.18.0
Prefix derivation changed from glued PascalCase (CliUtilityChangelog) to underscore-joined PascalCase (Cli_Utility_Changelog) in 0.18.0 so type names visibly mirror their file path. Existing type aliases must be renamed to the new form; the previous format is no longer accepted.