{"record":{"id":"873f781050decde0","repo":"oxc-project/oxc","slug":"unexpected-any-specify-a-different-type","errorCode":null,"errorMessage":"Unexpected `any`. Specify a different type.","messagePattern":"Unexpected `any`\\. Specify a different type\\.","errorType":"validation","errorClass":"OxcDiagnostic","httpStatus":null,"severity":"warning","filePath":"crates/oxc_linter/src/rules/typescript/no_explicit_any.rs","lineNumber":16,"sourceCode":"use oxc_ast::AstKind;\nuse oxc_diagnostics::OxcDiagnostic;\nuse oxc_macros::declare_oxc_lint;\nuse oxc_span::Span;\nuse schemars::JsonSchema;\nuse serde::Deserialize;\nuse serde_json::Value;\n\nuse crate::{\n    AstNode,\n    context::{ContextHost, LintContext},\n    rule::{DefaultRuleConfig, Rule},\n};\n\nfn no_explicit_any_diagnostic(span: Span) -> OxcDiagnostic {\n    OxcDiagnostic::warn(\"Unexpected `any`. Specify a different type.\")\n        .with_help(\"Use `unknown` instead, this will force you to explicitly, and safely, assert the type is correct.\")\n        .with_label(span)\n}\n\n#[derive(Debug, Default, Clone, JsonSchema, Deserialize)]\n#[serde(rename_all = \"camelCase\", default, deny_unknown_fields)]\npub struct NoExplicitAny {\n    /// Whether to enable auto-fixing in which the `any` type is converted to the `unknown` type.\n    fix_to_unknown: bool,\n    /// Whether to ignore rest parameter arrays.\n    ignore_rest_args: bool,\n}\n\ndeclare_oxc_lint!(\n    /// ### What it does\n    ///\n    /// Disallows explicit use of the `any` type.\n    ///","sourceCodeStart":1,"sourceCodeEnd":34,"githubUrl":"https://github.com/oxc-project/oxc/blob/e1e7af627c8843ab64044ed466b128fcc21a035b/crates/oxc_linter/src/rules/typescript/no_explicit_any.rs#L1-L34","documentation":"Oxlint's port of typescript-eslint's no-explicit-any. An explicit `any` annotation opts a value out of type checking entirely; the help at no_explicit_any.rs:18 recommends `unknown`, which forces an explicit, safe assertion. The config struct in the same file exposes fixToUnknown (autofix rewrites `any` to `unknown`) and ignoreRestArgs (skip rest parameter arrays).","triggerScenarios":"`function f(x: any) {}`, `const data: any = res.json()`, `Array<any>`, `function g(): any` - any explicit `any` in a type position; rest parameters are exempt only when ignoreRestArgs is enabled.","commonSituations":"Incremental JS-to-TS migrations, consuming untyped third-party libraries, quick prototypes where `any` creeps in, then strict CI configs (typescript-eslint strict, oxlint restriction set) rejecting the code.","solutions":["Replace `any` with `unknown` and narrow before use","Declare the real shape with an interface or type alias","Use generics to carry types through the function","Enable fixToUnknown: true so `oxlint --fix` rewrites annotations automatically","Disable once with `// oxlint-disable-next-line typescript/no-explicit-any`"],"exampleFix":"// before\nfunction getLen(input: any) {\n  return input.length;\n}\n\n// after\nfunction getLen(input: { length: number }) {\n  return input.length;\n}","handlingStrategy":"validation","validationCode":"// oxlintrc.json\n{\n  \"rules\": {\n    \"typescript/no-explicit-any\": [\"error\", { \"fixToUnknown\": true, \"ignoreRestArgs\": true }]\n  }\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Enable noImplicitAny and strict in tsconfig so implicit any is caught at compile time too","Type third-party boundaries once in a declarations file instead of `any` at each call site","Run `oxlint --fix` with fixToUnknown in pre-commit to auto-rewrite new `any`s"],"tags":["typescript","lint","any","type-safety"],"backgroundTag":"no-explicit-any","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"}