{"record":{"id":"72d2c91806acb0c4","repo":"oxc-project/oxc","slug":"do-not-use-banned-type-as-a-type-use-sugges","errorCode":null,"errorMessage":"Do not use {banned_type:?} as a type. Use \"{suggested_type}\" instead","messagePattern":"Do not use (.+?) as a type\\. Use \"(.+?)\" instead","errorType":"validation","errorClass":"OxcDiagnostic","httpStatus":null,"severity":"warning","filePath":"crates/oxc_linter/src/rules/typescript/ban_types.rs","lineNumber":14,"sourceCode":"use cow_utils::CowUtils;\nuse oxc_ast::{AstKind, ast::TSTypeName};\nuse oxc_diagnostics::OxcDiagnostic;\nuse oxc_macros::declare_oxc_lint;\nuse oxc_span::Span;\n\nuse crate::{\n    AstNode,\n    context::{ContextHost, LintContext},\n    rule::Rule,\n};\n\nfn type_diagnostic(banned_type: &str, suggested_type: &str, span: Span) -> OxcDiagnostic {\n    OxcDiagnostic::warn(format!(\n        \"Do not use {banned_type:?} as a type. Use \\\"{suggested_type}\\\" instead\"\n    ))\n    .with_help(format!(\"Replace {banned_type:?} with the lowercase primitive type \\\"{suggested_type}\\\".\"))\n    .with_note(format!(\"{banned_type} is a wrapper object type, while {suggested_type} is the primitive type. Using the primitive type is more idiomatic and avoids confusion between the object wrapper and the primitive value.\"))\n    .with_label(span)\n}\n\nfn type_literal(span: Span) -> OxcDiagnostic {\n    OxcDiagnostic::warn(\"Prefer explicitly define the object shape\")\n        .with_help(\"This type means \\\"any non-nullish value\\\", which is slightly better than 'unknown', but it's still a broad type\")\n        .with_label(span)\n}\n\nfn function(span: Span) -> OxcDiagnostic {\n    OxcDiagnostic::warn(\"Don't use `Function` as a type\")\n        .with_help(\"The `Function` type accepts any function-like value\")\n        .with_label(span)\n}","sourceCodeStart":1,"sourceCodeEnd":32,"githubUrl":"https://github.com/oxc-project/oxc/blob/e1e7af627c8843ab64044ed466b128fcc21a035b/crates/oxc_linter/src/rules/typescript/ban_types.rs#L1-L32","documentation":"Warning from typescript/ban-types via type_diagnostic() (crates/oxc_linter/src/rules/typescript/ban_types.rs:14). It fires when a wrapper object type — String, Number, Boolean, or BigInt — is used in a type position, suggesting the lowercase primitive instead. Note the message uses Rust's {:?} debug formatting, so the type name prints quoted: Do not use \"String\" as a type.","triggerScenarios":"Type annotations or type references using a capitalized wrapper: 'let s: String = \"x\"', 'function f(x: Number): Boolean', 'const b: BigInt = 1n' — any position where the rule's run hits a TSTypeReference naming a banned wrapper.","commonSituations":"Developers coming from Java/C# where boxed types are idiomatic; code generated from templates or JSDoc that capitalized primitives; inconsistent typing across a large migrated codebase.","solutions":["Change the annotation to the lowercase primitive: String→string, Number→number, Boolean→boolean, BigInt→bigint","Run a project-wide rename for the affected annotations (these are pure type-level changes with no runtime effect)","Only if you truly need the object wrapper (very rare), disable the rule for that line with an explained eslint-disable comment"],"exampleFix":"// before\nfunction len(s: String): Number {\n  return s.length;\n}\n\n// after\nfunction len(s: string): number {\n  return s.length;\n}","handlingStrategy":"validation","validationCode":"const WRAPPER = /:\\s*(String|Number|Boolean|BigInt)\\b/;\nfor (const line of source.split('\\n')) {\n  if (WRAPPER.test(line)) fail('wrapper object type in annotation', line);\n}","typeGuard":"const PRIMITIVES = new Set(['string', 'number', 'boolean', 'bigint', 'symbol', 'null', 'undefined']);\nfunction isPrimitiveTypeName(name: string): boolean {\n  return PRIMITIVES.has(name);\n}","tryCatchPattern":null,"preventionTips":["Normalize on lowercase primitive names in review checklists","Configure editor snippets/autocompletion so capitalized wrappers are rarely typed","Enable strict TypeScript so 'String' vs 'string' mismatches surface as compile errors too"],"tags":["typescript","oxlint","lint","ban-types","primitive-types","style"],"backgroundTag":"typescript-banned-types","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"}