oxc-project/oxc · warning · OxcDiagnostic

Unexpected `any`. Specify a different type.

Error message

Unexpected `any`. Specify a different type.

What it means

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).

Source

Thrown at crates/oxc_linter/src/rules/typescript/no_explicit_any.rs:16

use oxc_ast::AstKind;
use oxc_diagnostics::OxcDiagnostic;
use oxc_macros::declare_oxc_lint;
use oxc_span::Span;
use schemars::JsonSchema;
use serde::Deserialize;
use serde_json::Value;

use crate::{
    AstNode,
    context::{ContextHost, LintContext},
    rule::{DefaultRuleConfig, Rule},
};

fn no_explicit_any_diagnostic(span: Span) -> OxcDiagnostic {
    OxcDiagnostic::warn("Unexpected `any`. Specify a different type.")
        .with_help("Use `unknown` instead, this will force you to explicitly, and safely, assert the type is correct.")
        .with_label(span)
}

#[derive(Debug, Default, Clone, JsonSchema, Deserialize)]
#[serde(rename_all = "camelCase", default, deny_unknown_fields)]
pub struct NoExplicitAny {
    /// Whether to enable auto-fixing in which the `any` type is converted to the `unknown` type.
    fix_to_unknown: bool,
    /// Whether to ignore rest parameter arrays.
    ignore_rest_args: bool,
}

declare_oxc_lint!(
    /// ### What it does
    ///
    /// Disallows explicit use of the `any` type.
    ///

View on GitHub (pinned to e1e7af627c)

Solutions

  1. Replace `any` with `unknown` and narrow before use
  2. Declare the real shape with an interface or type alias
  3. Use generics to carry types through the function
  4. Enable fixToUnknown: true so `oxlint --fix` rewrites annotations automatically
  5. Disable once with `// oxlint-disable-next-line typescript/no-explicit-any`

Example fix

// before
function getLen(input: any) {
  return input.length;
}

// after
function getLen(input: { length: number }) {
  return input.length;
}
Defensive patterns

Strategy: validation

Validate before calling

// oxlintrc.json
{
  "rules": {
    "typescript/no-explicit-any": ["error", { "fixToUnknown": true, "ignoreRestArgs": true }]
  }
}

Prevention

When it happens

Trigger: `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.

Common situations: 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.

Related errors


AI-assisted analysis of oxc-project/oxc@e1e7af627c (2026-08-20). Data as JSON: /api/errors/873f781050decde0. Report an issue: GitHub.