{"record":{"id":"29c6e042e2f44c57","repo":"oxc-project/oxc","slug":"import-type-annotations-are-forbidden","errorCode":null,"errorMessage":"`import()` type annotations are forbidden.","messagePattern":"`import\\(\\)` type annotations are forbidden\\.","errorType":"validation","errorClass":"OxcDiagnostic","httpStatus":null,"severity":"warning","filePath":"crates/oxc_linter/src/rules/typescript/consistent_type_imports.rs","lineNumber":27,"sourceCode":"    ast::{\n        ImportDeclaration, ImportDeclarationSpecifier, ImportDefaultSpecifier,\n        ImportNamespaceSpecifier, ImportSpecifier, Statement,\n    },\n};\nuse oxc_diagnostics::OxcDiagnostic;\nuse 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)","sourceCodeStart":9,"sourceCodeEnd":45,"githubUrl":"https://github.com/oxc-project/oxc/blob/e1e7af627c8843ab64044ed466b128fcc21a035b/crates/oxc_linter/src/rules/typescript/consistent_type_imports.rs#L9-L45","documentation":"Oxlint's typescript/consistent-type-imports rule reports this when it visits a TSImportType node, i.e. a type written as import('module').Name, while disallowTypeAnnotations is enabled (the default). The rule wants type references to come from static `import type` declarations instead, because import() types hide dependencies from bundlers and are not erased as reliably. It is the oxlint port of @typescript-eslint/consistent-type-imports' disallowTypeAnnotations option.","triggerScenarios":"Linting a TypeScript file where a type position uses the import() form: `type T = import('./mod').Foo;`, `let x: import('mod').T`, or a function returning `import('mod').Type`, with the rule enabled and disallowTypeAnnotations true (default). The diagnostic fires directly from AstKind::TSImportType in the rule's run().","commonSituations":"Code ported from projects that used import() types to break circular type dependencies; types copied out of generated .d.ts files into app sources; enabling a stricter typescript category or migrating an existing @typescript-eslint config to oxlint without reviewing this option.","solutions":["Rewrite `type T = import('./mod').Foo;` as `import type { Foo } from './mod';` and use `Foo` directly","If the import() annotation must stay (e.g. legacy circular type reference), set \"disallowTypeAnnotations\": false in the rule options","Suppress the single occurrence with an `// oxlint-disable-next-line typescript/consistent-type-imports` comment"],"exampleFix":"// before\ntype Config = import('./config').UserConfig;\n\n// after\nimport type { UserConfig } from './config';\ntype Config = UserConfig;","handlingStrategy":"validation","validationCode":"// .oxlintrc.json — keep the guard on but make the policy explicit\n{\n  \"rules\": {\n    \"typescript/consistent-type-imports\": [\"warn\", { \"disallowTypeAnnotations\": true }]\n  }\n}\n\n// pre-commit gate: fail fast before import() types land\n// npx oxlint --type-aware-appropriate categories run in CI","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Configure editor snippets to emit `import type` rather than import() types","Run oxlint in CI with consistent-type-imports enabled so import() types never merge","When copying types out of .d.ts files, rewrite them as import type declarations in the same commit"],"tags":["typescript","lint","imports","type-import","oxlint"],"backgroundTag":"import-type-annotation-misuse","analyzedSha":"e1e7af627c8843ab64044ed466b128fcc21a035b","analyzedAt":"2026-08-20T07:01:07.079Z","contentChangedAt":"2026-08-20T07:01:07.079Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}