{"record":{"id":"2c7c4fc779d33433","repo":"oxc-project/oxc","slug":"prefer-using-a-top-level-type-only-import-instead","errorCode":null,"errorMessage":"Prefer using a top-level type-only import instead of inline type specifiers.","messagePattern":"Prefer using a top-level type-only import instead of inline type specifiers\\.","errorType":"validation","errorClass":"OxcDiagnostic","httpStatus":null,"severity":"warning","filePath":"crates/oxc_linter/src/rules/import/consistent_type_specifier_style.rs","lineNumber":47,"sourceCode":"    .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.\",\n            \"Replace inline type specifiers with a top‐level import type statement.\",\n        ),\n    };\n    OxcDiagnostic::warn(warn_msg).with_help(help_msg).with_label(span)\n}\n\n#[derive(Debug, Default, PartialEq, Clone, Serialize, Deserialize, JsonSchema)]\nenum Mode {\n    /// Prefer `import type { Foo } from 'foo'` for type imports.\n    #[default]\n    #[serde(rename = \"prefer-top-level\")]\n    TopLevel,\n    /// Prefer `import { type Foo } from 'foo'` for type imports.\n    #[serde(rename = \"prefer-inline\")]\n    Inline,\n    /// Prefer `import type { Foo } from 'foo'` when all named imports are types, but allow\n    /// `import { type Foo, bar } from 'foo'` when value imports are present.\n    #[serde(rename = \"prefer-top-level-if-only-type-imports\")]\n    TopLevelIfOnlyTypeImports,\n}\n\n#[derive(Debug, Default, Clone, Serialize, Deserialize)]","sourceCodeStart":29,"sourceCodeEnd":65,"githubUrl":"https://github.com/oxc-project/oxc/blob/e1e7af627c8843ab64044ed466b128fcc21a035b/crates/oxc_linter/src/rules/import/consistent_type_specifier_style.rs#L29-L65","documentation":"The default `prefer-top-level` mode of `import/consistent-type-specifier-style`: inline type specifiers must be lifted into a dedicated top-level `import type` statement, which erases cleanly under TypeScript's `isolatedModules`/verbatim semantics. Declaration-file imports are already required to be top-level.","triggerScenarios":"`import { type Foo, bar } from 'foo';` with the rule at default settings (or explicitly prefer-top-level) and a non-declaration-file source.","commonSituations":"Codebases adopting isolatedModules or VerbatimModuleSyntax where inline specifier churn matters; mixed styles after team merges; default-enabled configs flagging older inline syntax.","solutions":["Split into `import type { Foo } from 'foo';` plus `import { bar } from 'foo';`","Run `oxlint --fix` — the fixer regenerates both statements","If the inline style is preferred repo-wide, switch the rule to prefer-inline instead"],"exampleFix":"// before\nimport { type Foo, bar } from 'foo';\n\n// after\nimport type { Foo } from 'foo';\nimport { bar } from 'foo';","handlingStrategy":"validation","validationCode":"// .oxlintrc.json (default mode)\n{\n  \"plugins\": [\"import\"],\n  \"rules\": { \"import/consistent-type-specifier-style\": \"warn\" }\n}\n// CI gate: npx oxlint src/","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Default prefer-top-level pairs well with isolatedModules/verbatimModuleSyntax","Run oxlint --fix after enabling to convert inline specifiers repo-wide","Keep type and value imports on separate statements when in doubt","Re-run the linter after any codemod that touches import statements"],"tags":["lint","oxlint","import-plugin","typescript","esm","style"],"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-14T00:17:10.932Z"}