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?
- Centralizes all types in
.d.tsfiles so the type layer is clearly separated from code. - Makes refactoring safer because types have single definitions rather than scattered inline copies.
- 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.
| 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 on a
.d.tsfile — 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
: MyTypeare allowed — Only plainTSTypeReferencewithout type arguments passes. Generics like: Map<K, V>are still flagged because the type arguments are inline. as constis allowed — Theas constassertion is a plain type reference with no type arguments, so it passes.as SomeType<T>is allowed whenTis a type parameter — Generic type arguments that reference enclosing type parameters are considered dynamic dependencies and are not flagged.