{"record":{"id":"2ba1e09b027ea1e7","repo":"oxc-project/oxc","slug":"all-imports-in-the-declaration-are-only-used-as-ty","errorCode":null,"errorMessage":"All imports in the declaration are only used as types. Use `import type`.","messagePattern":"All imports in the declaration are only used as types\\. Use `import type`\\.","errorType":"validation","errorClass":"OxcDiagnostic","httpStatus":null,"severity":"warning","filePath":"crates/oxc_linter/src/rules/typescript/consistent_type_imports.rs","lineNumber":38,"sourceCode":"    AstNode,\n    context::{ContextHost, LintContext},\n    fixer::{RuleFix, RuleFixer},\n    rule::{DefaultRuleConfig, Rule},\n};\n\nfn no_import_type_annotations_diagnostic(span: Span) -> OxcDiagnostic {\n    OxcDiagnostic::warn(\"`import()` type annotations are forbidden.\")\n        .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`.\")\n        .with_label(span)\n}\n\nfn avoid_import_type_diagnostic(span: Span) -> OxcDiagnostic {\n    OxcDiagnostic::warn(\"Use an `import` instead of an `import type`.\")\n        .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'`.\")\n        .with_label(span)\n}\nfn type_over_value_diagnostic(span: Span) -> OxcDiagnostic {\n    OxcDiagnostic::warn(\"All imports in the declaration are only used as types. Use `import type`.\")\n        .with_help(\"Replace the `import` declaration with `import type`. For example, change `import { Type } from 'module'` would become `import type { Type } from 'module'`.\")\n        .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.\")\n        .with_label(span)\n}\n\nfn some_imports_are_only_types_diagnostic(span: Span, type_imports: &str) -> OxcDiagnostic {\n    OxcDiagnostic::warn(format!(\"Imports {type_imports} are only used as type.\")).with_label(span)\n}\n\n#[derive(Debug, Default, Clone, Deserialize)]\npub struct ConsistentTypeImports(Box<ConsistentTypeImportsConfig>);\n\nimpl Deref for ConsistentTypeImports {\n    type Target = ConsistentTypeImportsConfig;\n\n    fn deref(&self) -> &Self::Target {\n        &self.0\n    }","sourceCodeStart":20,"sourceCodeEnd":56,"githubUrl":"https://github.com/oxc-project/oxc/blob/e1e7af627c8843ab64044ed466b128fcc21a035b/crates/oxc_linter/src/rules/typescript/consistent_type_imports.rs#L20-L56","documentation":"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.","triggerScenarios":"`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';`.","commonSituations":"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.","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';`)"],"exampleFix":"// before\nimport { Foo } from './foo';\nlet x: Foo;\n\n// after\nimport type { Foo } from './foo';\nlet x: Foo;","handlingStrategy":"validation","validationCode":"// Run the linter as a gate; the rule ships an autofix:\n// package.json\n\"scripts\": { \"lint:fix\": \"oxlint --fix\" }\n\n// .oxlintrc.json (choose one fix style for the whole repo)\n{\n  \"rules\": {\n    \"typescript/consistent-type-imports\": [\n      \"warn\", { \"prefer\": \"type-imports\", \"fixStyle\": \"separate-type-imports\" }\n    ]\n  }\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["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"],"tags":["typescript","lint","imports","type-import","tree-shaking","oxlint"],"backgroundTag":"type-import-style","analyzedSha":"e1e7af627c8843ab64044ed466b128fcc21a035b","analyzedAt":"2026-08-20T07:01:07.079Z","contentChangedAt":"2026-08-20T07:01:07.079Z","schemaVersion":2},"datasetVersion":"2026-09-14T00:17:10.932Z"}