Skip to content
← Back to rules

import/consistent-type-specifier-style Style

🛠️ An auto-fix is available for this rule for some violations.

What it does ​

Enforces or bans the use of inline type-only markers for named imports.

Why is this bad? ​

Mixing top-level import type { Foo } from 'foo' with inline { type Bar } forces readers to mentally switch contexts when scanning your imports. Enforcing one style makes it immediately obvious which imports are types and which are value imports.

Examples ​

Examples of incorrect code for the default prefer-top-level option:

typescript
import { type Foo } from "Foo";
import Foo, { type Bar } from "Foo";

Examples of correct code for the default option:

typescript
import type { Foo } from 'Foo';
import type Foo, { Bar } from 'Foo';

Examples of incorrect code for the prefer-top-level-if-only-type-imports option:

typescript
import { type Foo } from "Foo";
import { type Foo, type Bar } from "Foo";

Examples of correct code for the prefer-top-level-if-only-type-imports option:

typescript
import type { Foo } from 'Foo';
import { type Foo, someValue } from 'Foo';
import type Foo, { Bar } from 'Foo';

Examples of incorrect code for the prefer-inline option:

typescript
import type { Foo } from 'Foo';
import type Foo, { Bar } from 'Foo';

Examples of correct code for the prefer-inline option:

typescript
import { type Foo } from "Foo";
import Foo, { type Bar } from "Foo";

Configuration ​

This rule accepts one of the following string values:

"prefer-top-level" ​

Prefer import type { Foo } from 'foo' for type imports.

"prefer-inline" ​

Prefer import { type Foo } from 'foo' for type imports.

"prefer-top-level-if-only-type-imports" ​

Prefer import type { Foo } from 'foo' when all named imports are types, but allow import { type Foo, bar } from 'foo' when value imports are present.

How to use ​

To enable this rule using the config file or in the CLI, you can use:

json
{
  "plugins": ["import"],
  "rules": {
    "import/consistent-type-specifier-style": "error"
  }
}
ts
import { defineConfig } from "oxlint";

export default defineConfig({
  plugins: ["import"],
  rules: {
    "import/consistent-type-specifier-style": "error",
  },
});
bash
oxlint --deny import/consistent-type-specifier-style --import-plugin

Version ​

This rule was added in v0.16.11.

References ​