{"record":{"id":"a7857ffd32bc90b8","repo":"oxc-project/oxc","slug":"use-an-import-instead-of-an-import-type","errorCode":null,"errorMessage":"Use an `import` instead of an `import type`.","messagePattern":"Use an `import` instead of an `import type`\\.","errorType":"validation","errorClass":"OxcDiagnostic","httpStatus":null,"severity":"warning","filePath":"crates/oxc_linter/src/rules/typescript/consistent_type_imports.rs","lineNumber":33,"sourceCode":"use oxc_macros::declare_oxc_lint;\nuse oxc_semantic::{Reference, SymbolId};\nuse oxc_span::{GetSpan, Span};\n\nuse crate::{\n    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 {","sourceCodeStart":15,"sourceCodeEnd":51,"githubUrl":"https://github.com/oxc-project/oxc/blob/e1e7af627c8843ab64044ed466b128fcc21a035b/crates/oxc_linter/src/rules/typescript/consistent_type_imports.rs#L15-L51","documentation":"Emitted by typescript/consistent-type-imports when the rule is configured with \"prefer\": \"no-type-imports\" and the file contains an `import type` declaration. Under that convention types must travel through regular value imports, so any type-only import declaration (or a specifier carrying the inline `type` modifier) is reported. The run() checks ImportDeclaration and its specifiers whenever prefer is Prefer::NoTypeImports.","triggerScenarios":"A .oxlintrc.json sets \"typescript/consistent-type-imports\": [\"error\", { \"prefer\": \"no-type-imports\" }] and the source has `import type { Foo } from './foo';` or `import { type Foo } from './foo';`. Each such declaration or type-marked specifier produces this diagnostic.","commonSituations":"Migrating an ESLint config where a sub-project chose no-type-imports; mixing teams with different verbatimModuleSyntax settings; auto-fixers or editors inserting `import type` while the repo convention forbids it.","solutions":["Change `import type { Foo } from './foo';` to `import { Foo } from './foo';` and drop inline `type` modifiers","If the repo actually prefers type-only imports, set \"prefer\": \"type-imports\" (the default) instead","Override the rule only for the affected paths via oxlint config overrides, or disable it for that file with an oxlint-disable comment"],"exampleFix":"// before\nimport type { Foo } from './foo';\n\n// after\nimport { Foo } from './foo';","handlingStrategy":"validation","validationCode":"// Decide the convention once and encode it, so the diagnostic is expected:\n// .oxlintrc.json\n{\n  \"rules\": {\n    \"typescript/consistent-type-imports\": [\"warn\", { \"prefer\": \"no-type-imports\" }]\n  }\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Match the prefer option to your tsconfig: use no-type-imports only when verbatimModuleSyntax is off","Teach editor auto-imports the repo convention (vscode-typescript preferences.importModuleSpecifier) so tooling does not fight the rule","Document the chosen import style in the contributing guide next to the lint rule that enforces it"],"tags":["typescript","lint","imports","type-import","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"}