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 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?

  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 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-utility becomes MyUtility), 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: MDXComponents produces MdxComponents, not MDXComponents.
  • 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.
  • Rule does not fire on a .d.ts file outside a types/ 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.ts files use the directory prefix — A path segment named index is dropped when deriving the prefix, so types/cli/utility/index.d.ts expects the prefix Cli_Utility (the same as the directory), not Cli_Utility_Index.
  • 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.
  • invalidIdentifierPrefix reported on the file itself — The first path segment after types/ 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.