eslint-plugin-type-imports
v2.0.0
Published
An eslint plugin to enforce consistent usage of TypeScript type imports
Maintainers
Readme
eslint-plugin-type-imports
An ESLint plugin to enforce consistent usage of TypeScript type imports.
Installation
npm install --save-dev eslint-plugin-type-importsConfiguration
Add the plugin to your ESLint config (eslint.config.js):
import typeImports from 'eslint-plugin-type-imports'
export default [
// ... other configs
typeImports.configs.recommended,
]Rules
enforce-consistent-type-keyword-in-imports
Enforces that type imports use the type keyword outside of curly braces rather than inline on each specifier.
Bad:
import { type User } from './types'
import { type User, type Post } from './types'Good:
import type { User } from './types'
import type { User, Post } from './types'prevent-duplicate-imports
Prevents multiple import statements from the same package or path. The auto-fix merges them into a single import.
Bad:
import { a } from './utils'
import { b } from './utils'Good:
import { a, b } from './utils'Type imports are handled correctly:
// Two type-only imports are merged with the type keyword preserved
import type { A } from './types'
import type { B } from './types'
// → import type { A, B } from './types'
// Mixed value and type imports are merged with inline type specifiers
import { a } from './utils'
import type { B } from './utils'
// → import { a, type B } from './utils'Default imports are merged with named imports:
import def from './module'
import { a } from './module'
// → import def, { a } from './module'Note: Namespace imports (
import * as ns) and side-effect imports (import './module') are excluded from this rule and left as-is.
License
MIT
