Skip to main content

No Inline Type Annotation

Require named type aliases instead of inline type annotations in code files so every type is defined in a .d.ts file.

Summary

The no-inline-type-annotation rule reports any type annotation or as assertion that is not a plain TSTypeReference without concrete type arguments.

Arrays, unions, intersections, object literals, tuples, generics, function types, and primitive keywords are all flagged — both in the : Type annotation position and the as Type assertion position.

Generic type arguments that reference enclosing type parameters (e.g., as SomeType<T> inside a function f<T>()) are allowed because the dependency is dynamic.

The rule skips .d.ts files where inline types are expected.

Why Use This Rule?

  1. Centralizes all types in .d.ts files so the type layer is clearly separated from code.
  2. Makes refactoring safer because types have single definitions rather than scattered inline copies.
  3. Produces descriptive type names that document what each variable represents.

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 on a .d.ts file — The rule skips files ending in .d.ts. If the warning fires anyway, verify that the file extension is correct and that the filename reaches the rule.
  • Simple type references like : MyType are allowed — Only plain TSTypeReference without type arguments passes. Generics like : Map<K, V> are still flagged because the type arguments are inline.
  • as const is allowed — The as const assertion is a plain type reference with no type arguments, so it passes.
  • as SomeType<T> is allowed when T is a type parameter — Generic type arguments that reference enclosing type parameters are considered dynamic dependencies and are not flagged.