close

consistent-type-imports

Added in v0.1.14

Configuration

rslint.config.ts
import { defineConfig, ts } from '@rslint/core';

export default defineConfig([
  ts.configs.recommended,
  {
    rules: {
      '@typescript-eslint/consistent-type-imports': 'error',
    },
  },
]);

Rule Details

Enforce consistent use of type-only imports. TypeScript erases imports marked with type, which makes their runtime behavior explicit and works with module settings that preserve value imports.

Examples of incorrect code for this rule with the default options:

import { Model, createModel } from './models';

export function create(): Model {
  return createModel();
}

type External = import('./external').External;

Examples of correct code for this rule with the default options:

import type { Model } from './models';
import { createModel } from './models';

export function create(): Model {
  return createModel();
}

prefer

The default, "type-imports", requires imports used only in type positions to be marked as type-only. "no-type-imports" instead forbids both top-level and inline type modifiers.

{
  "consistent-type-imports": ["error", { "prefer": "no-type-imports" }]
}
import { Model } from './models';

type LocalModel = Model;

fixStyle

When prefer is "type-imports", "separate-type-imports" (the default) moves type-only names into a separate declaration. "inline-type-imports" keeps named type imports in the value declaration when possible.

{
  "consistent-type-imports": [
    "error",
    { "fixStyle": "inline-type-imports" }
  ]
}
import { type Model, createModel } from './models';

disallowTypeAnnotations

disallowTypeAnnotations defaults to true and reports import() type annotations. Set it to false to allow them.

{
  "consistent-type-imports": [
    "error",
    { "disallowTypeAnnotations": false }
  ]
}
type Model = import('./models').Model;

Differences from ESLint

The pinned upstream implementation stores module sources in a plain JavaScript object, so imports from "constructor", "toString", "__proto__", or "hasOwnProperty" throw while linting. The Go map intentionally handles these names normally and still reports and fixes the import.

With "inline-type-imports", rslint also emits a valid inline fix when an earlier default-only or default-plus-namespace value import from the same module causes the pinned upstream implementation to suppress its fix.

Original Documentation