{"record":{"id":"a8da86c4e6117b28","repo":"oxc-project/oxc","slug":"don-t-use-function-as-a-type","errorCode":null,"errorMessage":"Don't use `Function` as a type","messagePattern":"Don't use `Function` as a type","errorType":"validation","errorClass":"OxcDiagnostic","httpStatus":null,"severity":"warning","filePath":"crates/oxc_linter/src/rules/typescript/ban_types.rs","lineNumber":29,"sourceCode":"};\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}\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.","sourceCodeStart":11,"sourceCodeEnd":47,"githubUrl":"https://github.com/oxc-project/oxc/blob/e1e7af627c8843ab64044ed466b128fcc21a035b/crates/oxc_linter/src/rules/typescript/ban_types.rs#L11-L47","documentation":"Warning from typescript/ban-types via function() (crates/oxc_linter/src/rules/typescript/ban_types.rs:29). It fires when 'Function' is used as a type: Function accepts any callable and its parameters/return are implicitly 'any', defeating type checking at the call boundary.","triggerScenarios":"A type reference to the global Function name: 'const cb: Function = () => {}', 'register(handler: Function)', or 'new Map<string, Function>()' — hit wherever the rule resolves the identifier to the banned global.","commonSituations":"Callback-heavy APIs written before typed signatures were established; quick 'any function' placeholders in event registries or plugin systems; ported JavaScript with minimal typing.","solutions":["Replace with a concrete signature matching the expected shape, e.g. '() => void' or '(event: Event) => void'","For truly arbitrary callables use '(...args: unknown[]) => unknown'","Define a named call-signature interface when the same function shape repeats"],"exampleFix":"// before\nconst cb: Function = () => console.log('hi');\n\n// after\nconst cb: () => void = () => console.log('hi');","handlingStrategy":"type-guard","validationCode":"const FN = /:\\s*Function\\b/;\nfor (const line of source.split('\\n')) {\n  if (FN.test(line)) fail('untyped Function used as a type', line);\n}","typeGuard":"function isCallableOf<S extends (...args: never[]) => unknown>(v: unknown): v is S {\n  return typeof v === 'function';\n}","tryCatchPattern":null,"preventionTips":["Type callbacks with their real signature ('(e: Event) => void') at the boundary","Use '(...args: unknown[]) => unknown' for genuinely arbitrary callables","Search for ': Function' before merging branches"],"tags":["typescript","oxlint","lint","ban-types","function-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-14T00:17:10.932Z"}