consistent-type-specifier-style
Added in v0.9.4Configuration
Rule Details
Enforces a consistent position for type markers in named imports. This rule is automatically fixable and does not require type information.
Default imports, namespace imports, side-effect imports, and empty imports do not need named type markers. The fixer can leave extra spaces. It does not merge duplicate import declarations; use import/no-duplicates to enforce that separately.
Options
The rule accepts one string:
"prefer-inline": puttypeon each named type import."prefer-top-level": use a separateimport typedeclaration.
When the option is omitted, the rule behaves as "prefer-top-level", matching eslint-plugin-import v2.32.0's runtime. Its upstream documentation and schema advertise "prefer-inline" as the default; specify the option explicitly to choose that style.
prefer-inline
Examples of incorrect code for this rule with the "prefer-inline" option:
Examples of correct code for this rule with the "prefer-inline" option:
prefer-top-level
Examples of incorrect code for this rule with the "prefer-top-level" option:
Examples of correct code for this rule with the "prefer-top-level" option:
Differences from ESLint
-
Flow
typeofimports are unsupported. This rule supports TypeScript type imports, but not Flow'simport typeof Foo from 'foo'orimport { typeof Foo } from 'foo'forms. -
Imports with attributes are not autofixed. Imports with
with { ... }, includingimport typedeclarations with a"resolution-mode"attribute, are reported without an automatic fix to preserve their module resolution and avoid invalid TypeScript. -
Autofixes do not delete comments. For example,
import { type /*A*/ Foo /*B*/ as /*C*/ Bar } from 'm';is reported without a fix under"prefer-top-level". Fixes remain available when the comments can stay in place. -
Autofixes preserve quoted import names. With
"prefer-top-level", rslint keeps the original name and its quotes. eslint-plugin-import v2.32.0 replaces'a-b'withundefinedin this case, which changes the imported name: