{"record":{"id":"2f1a7ebdd2422c9e","repo":"oxc-project/oxc","slug":"type-imports-from-declaration-files-must-use-top-l","errorCode":null,"errorMessage":"Type imports from declaration files must use top-level `import type` syntax.","messagePattern":"Type imports from declaration files must use top-level `import type` syntax\\.","errorType":"validation","errorClass":"OxcDiagnostic","httpStatus":null,"severity":"warning","filePath":"crates/oxc_linter/src/rules/import/consistent_type_specifier_style.rs","lineNumber":25,"sourceCode":"    builder::AstBuilder,\n};\nuse oxc_codegen::{Context, Gen};\nuse oxc_diagnostics::OxcDiagnostic;\nuse oxc_macros::declare_oxc_lint;\nuse oxc_span::{FileExtension, GetSpan, SPAN, Span};\nuse schemars::JsonSchema;\nuse serde::{Deserialize, Serialize};\nuse serde_json::Value;\n\nuse crate::{\n    AstNode,\n    context::LintContext,\n    fixer::RuleFixer,\n    rule::{DefaultRuleConfig, Rule},\n};\n\nfn use_top_level_for_declaration_file_import_diagnostic(span: Span) -> OxcDiagnostic {\n    OxcDiagnostic::warn(\n        \"Type imports from declaration files must use top-level `import type` syntax.\",\n    )\n    .with_help(\"Replace inline type specifiers with a top-level import type statement.\")\n    .with_label(span)\n}\n\nfn consistent_type_specifier_style_diagnostic(span: Span, mode: &Mode) -> OxcDiagnostic {\n    let (warn_msg, help_msg) = match mode {\n        Mode::Inline => (\n            \"Prefer using inline type specifiers instead of a top-level type-only import.\",\n            \"Replace top‐level import type with an inline type specifier.\",\n        ),\n        Mode::TopLevel => (\n            \"Prefer using a top-level type-only import instead of inline type specifiers.\",\n            \"Replace inline type specifiers with a top‐level import type statement.\",\n        ),\n        Mode::TopLevelIfOnlyTypeImports => (\n            \"Prefer using a top-level type-only import instead of inline type specifiers when there are only type imports.\",","sourceCodeStart":7,"sourceCodeEnd":43,"githubUrl":"https://github.com/oxc-project/oxc/blob/e1e7af627c8843ab64044ed466b128fcc21a035b/crates/oxc_linter/src/rules/import/consistent_type_specifier_style.rs#L7-L43","documentation":"oxlint's port of `import/consistent-type-specifier-style`. Independently of the configured mode, type imports from TypeScript declaration files (detected via `is_ts_declaration` on the resolved file extension, e.g. `.d.ts`) must use the top-level `import type` form; inline type specifiers on declaration-file imports are always reported by `use_top_level_for_declaration_file_import_diagnostic`.","triggerScenarios":"`import { type Foo } from './types.d.ts';` under any mode — prefer-top-level (default), prefer-inline, or prefer-top-level-if-only-type-imports. The declaration-file check runs regardless of the mode option.","commonSituations":"Projects importing hand-written `.d.ts` ambient modules; type-only imports from `.d.mts`/`.d.cts` files; switching a repo to prefer-inline and discovering the declaration-file exception.","solutions":["Rewrite as `import type { Foo } from './types.d.ts';` (the rule ships a fixer that regenerates the statement)","Keep any value imports from the same file in a separate non-type import statement","Run `oxlint --fix` to convert all declaration-file imports at once"],"exampleFix":"// before\nimport { type Foo, type Bar } from './types.d.ts';\n\n// after\nimport type { Foo, Bar } from './types.d.ts';","handlingStrategy":"validation","validationCode":"// .oxlintrc.json\n{\n  \"plugins\": [\"import\"],\n  \"rules\": { \"import/consistent-type-specifier-style\": \"warn\" }\n}\n// CI gate: npx oxlint src/","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Treat .d.ts imports as always requiring top-level import type, regardless of repo mode","Let oxlint --fix convert statements mechanically instead of hand-editing","Document the chosen specifier style in CONTRIBUTING so codemods and humans agree","Keep the import plugin enabled in CI for all pull requests"],"tags":["lint","oxlint","import-plugin","typescript","esm","dts"],"backgroundTag":"type-only-import-style","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"}