{"record":{"id":"c81a1788d4c791a0","repo":"oxc-project/oxc","slug":"prefer-using-a-top-level-type-only-import-instead-c81a17","errorCode":null,"errorMessage":"Prefer using a top-level type-only import instead of inline type specifiers when there are only type imports.","messagePattern":"Prefer using a top-level type-only import instead of inline type specifiers when there are only type imports\\.","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 `prefer-top-level-if-only-type-imports` mode of `import/consistent-type-specifier-style`: when every specifier in an import statement is a type, the statement must be a top-level `import type`; statements mixing type and value specifiers may keep inline specifiers.","triggerScenarios":"`import { type Foo, type Bar } from 'foo';` with the rule configured as prefer-top-level-if-only-type-imports and a non-declaration-file source.","commonSituations":"Teams that want the erasure safety of top-level type imports without forcing statement splits on mixed imports; gradual migrations away from inline style.","solutions":["Rewrite all-type statements as `import type { Foo, Bar } from 'foo';`","Leave genuinely mixed type/value statements as they are — this mode permits inline there","Use `oxlint --fix` to convert every all-type statement in one pass"],"exampleFix":"// before — every specifier in the statement is a type\nimport { type Foo, type Bar } from 'foo';\n\n// after\nimport type { Foo, Bar } from 'foo';","handlingStrategy":"validation","validationCode":"// .oxlintrc.json\n{\n  \"plugins\": [\"import\"],\n  \"rules\": { \"import/consistent-type-specifier-style\": [\"warn\", \"prefer-top-level-if-only-type-imports\"] }\n}\n// CI gate: npx oxlint src/","typeGuard":null,"tryCatchPattern":null,"preventionTips":["All-type import statements should read import type { ... }; mixed statements may stay inline","Use the fixer for bulk conversion when adopting the mode","Keep the import plugin enabled in CI for all pull requests","Align the mode with the team's isolatedModules settings"],"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-14T05:17:10.506Z"}