oxc-project/oxc · warning · OxcDiagnostic
All imports in the declaration are only used as types. Use `
Error message
All imports in the declaration are only used as types. Use `import type`.
What it means
Default-mode diagnostic of typescript/consistent-type-imports ("prefer": "type-imports"): an import declaration whose every specifier is referenced only in type positions must be written as `import type`. The rule's note explains the rationale: tree-shaking, explicit signal that runtime code does not depend on the module, and bundler elimination of unused type imports.
Source
Thrown at crates/oxc_linter/src/rules/typescript/consistent_type_imports.rs:38
AstNode,
context::{ContextHost, LintContext},
fixer::{RuleFix, RuleFixer},
rule::{DefaultRuleConfig, Rule},
};
fn no_import_type_annotations_diagnostic(span: Span) -> OxcDiagnostic {
OxcDiagnostic::warn("`import()` type annotations are forbidden.")
.with_help("Replace `import()` type annotations with a regular type import. For example, change `type T = import('module').Type` to `import type { Type } from 'module'; type T = Type`.")
.with_label(span)
}
fn avoid_import_type_diagnostic(span: Span) -> OxcDiagnostic {
OxcDiagnostic::warn("Use an `import` instead of an `import type`.")
.with_help("Replace the `import type` declaration with a regular `import` declaration. For example, `import type { Type } from 'module'` would become `import { Type } from 'module'`.")
.with_label(span)
}
fn type_over_value_diagnostic(span: Span) -> OxcDiagnostic {
OxcDiagnostic::warn("All imports in the declaration are only used as types. Use `import type`.")
.with_help("Replace the `import` declaration with `import type`. For example, change `import { Type } from 'module'` would become `import type { Type } from 'module'`.")
.with_note("Using `import type` for type-only imports helps with tree-shaking, makes it clear that these imports don't affect runtime code, and can improve build performance by allowing bundlers to eliminate unused type imports.")
.with_label(span)
}
fn some_imports_are_only_types_diagnostic(span: Span, type_imports: &str) -> OxcDiagnostic {
OxcDiagnostic::warn(format!("Imports {type_imports} are only used as type.")).with_label(span)
}
#[derive(Debug, Default, Clone, Deserialize)]
pub struct ConsistentTypeImports(Box<ConsistentTypeImportsConfig>);
impl Deref for ConsistentTypeImports {
type Target = ConsistentTypeImportsConfig;
fn deref(&self) -> &Self::Target {
&self.0
}View on GitHub (pinned to e1e7af627c)
Solutions
- Run `oxlint --fix` or manually add `type`: `import type { Foo } from './foo';`
- If you prefer inline markers, configure "fixStyle": "inline-type-imports" and write `import { type Foo } from './foo';`
- If the module genuinely has a runtime side effect you need, keep the value import and add the side-effect usage explicitly (e.g. `import './foo';`)
Example fix
// before
import { Foo } from './foo';
let x: Foo;
// after
import type { Foo } from './foo';
let x: Foo; Defensive patterns
Strategy: validation
Validate before calling
// Run the linter as a gate; the rule ships an autofix:
// package.json
"scripts": { "lint:fix": "oxlint --fix" }
// .oxlintrc.json (choose one fix style for the whole repo)
{
"rules": {
"typescript/consistent-type-imports": [
"warn", { "prefer": "type-imports", "fixStyle": "separate-type-imports" }
]
}
} Prevention
- Enable verbatimModuleSyntax in tsconfig so the compiler also fails on unmarked type-only imports, not just the linter
- Run `oxlint --fix` in a pre-commit hook so imports converge automatically
- When deleting the last value usage of an import, check whether the import should become `import type` in the same change
When it happens
Trigger: `import { Foo } from './foo';` where semantic analysis finds no value reference to Foo anywhere in the file, with prefer set to type-imports (default). The whole declaration is reported and, with the default fixStyle separate-type-imports, rewritten to `import type { Foo } from './foo';`.
Common situations: Enabling the rule on an existing codebase where types were imported casually; deleting the last value usage of an import (e.g. removing a class usage but keeping the type usage); switching to verbatimModuleSyntax or isolatedModules where unmarked type imports become build errors or runtime failures.
Related errors
- `import()` type annotations are forbidden.
- Use an `import` instead of an `import type`.
- Imports {type_imports} are only used as type.
- Usage of namespaced aka wildcard \"*\" imports prohibited
- TypeScript will only remove the inline type specifiers which
AI-assisted analysis of oxc-project/oxc@e1e7af627c (2026-08-20).
Data as JSON: /api/errors/2ba1e09b027ea1e7.
Report an issue: GitHub.