{"record":{"id":"8578dc4f0ad680ed","repo":"oxc-project/oxc","slug":"the-object-type-actually-means-any-non-nullish","errorCode":null,"errorMessage":"'The `Object` type actually means \"any non-nullish value\"","messagePattern":"'The `Object` type actually means \"any non-nullish value\"","errorType":"validation","errorClass":"OxcDiagnostic","httpStatus":null,"severity":"warning","filePath":"crates/oxc_linter/src/rules/typescript/ban_types.rs","lineNumber":35,"sourceCode":"    .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}\n\nfn object(span: Span) -> OxcDiagnostic {\n    OxcDiagnostic::warn(\"'The `Object` type actually means \\\"any non-nullish value\\\"\")\n        .with_help(\"Replace `Object` with a more specific type. If you need a generic object, use `Record<string, unknown>` or define an interface/type with explicit properties. If you need any value, use `unknown` instead.\")\n        .with_note(\"The `Object` type is confusing because it doesn't mean 'any object' - it means 'any non-nullish value', which includes primitives. This makes code harder to understand and can lead to unexpected behavior.\")\n        .with_label(span)\n}\n\n#[derive(Debug, Default, Clone)]\npub struct BanTypes;\n\ndeclare_oxc_lint!(\n    /// ### What it does\n    ///\n    /// This rule bans specific types and can suggest alternatives. Note that it does not ban the corresponding runtime objects from being used.\n    ///\n    /// ::: warning\n    /// This rule is deprecated and will be removed in a future release.\n    ///\n    /// Prefer these replacement rules:\n    /// - `typescript/no-empty-object-type`","sourceCodeStart":17,"sourceCodeEnd":53,"githubUrl":"https://github.com/oxc-project/oxc/blob/e1e7af627c8843ab64044ed466b128fcc21a035b/crates/oxc_linter/src/rules/typescript/ban_types.rs#L17-L53","documentation":"Warning from typescript/ban-types via object() (crates/oxc_linter/src/rules/typescript/ban_types.rs:35). It fires when 'Object' is used as a type: Object means 'any non-nullish value' (including primitives), not 'any object'. The message text carries a stray leading apostrophe (\"'The `Object` type actually means...\") — a cosmetic string quirk in the rule, the diagnostic itself is correct.","triggerScenarios":"A type reference to the global Object name: 'function g(o: Object) {}', 'const opts: Object = {}', 'Object' as a generic type argument — wherever the rule matches the banned global identifier in a type position.","commonSituations":"Java-influenced code where Object is the catch-all parameter type; loosely typed public APIs; Object-keys/Object-entries utilities annotated with Object instead of Record<string, unknown>.","solutions":["Use 'Record<string, unknown>' for dictionary-style values","Declare an interface/type with the actual members you rely on","Use 'unknown' when the value is genuinely opaque and narrow with type guards"],"exampleFix":"// before\nfunction g(o: Object) {\n  console.log(o);\n}\n\n// after\nfunction g(o: Record<string, unknown>) {\n  console.log(o);\n}","handlingStrategy":"validation","validationCode":"const OBJ = /:\\s*Object\\b/;\nfor (const line of source.split('\\n')) {\n  if (OBJ.test(line)) fail('Object used as a type; use Record<string, unknown> or an interface', line);\n}","typeGuard":"function isRecord(v: unknown): v is Record<string, unknown> {\n  return typeof v === 'object' && v !== null && !Array.isArray(v);\n}","tryCatchPattern":null,"preventionTips":["Prefer interfaces for known shapes and Record<string, unknown> for dictionaries","Use Object.keys/Object.entries on values, never 'Object' as a type","Review code ported from Java-style codebases for capitalized catch-all types"],"tags":["typescript","oxlint","lint","ban-types","object-type","type-safety"],"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-14T05:17:10.506Z"}