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 that is not a plain TSTypeReference without type arguments. Arrays, unions, intersections, object literals, tuples, generics, function types, and primitive keywords are all flagged. 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
- Correct
- Incorrect
// Named type from a .d.ts file.
const entries: RunnerParseEntries = [];
const config: RunnerRunConfig = JSON.parse(raw);
let selectedPackage: RunnerRunSelectedPackage;
const entries: string[] = [];
let x: string | undefined;
const m: Map<string, number> = new Map();
const name: string = '';
const obj: { name: string } = { name: 'test' };
Configuration
Enable the rule in your ESLint flat config:
import { noInlineTypeAnnotation } from '@cbnventures/nova/rules/eslint';
export default [
{
plugins: {
'@cbnventures/nova': {
rules: {
'no-inline-type-annotation': noInlineTypeAnnotation,
},
},
},
rules: {
'@cbnventures/nova/no-inline-type-annotation': ['warn'],
},
},
];
This rule has no additional options.
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.