oxc-project/oxc · warning · OxcDiagnostic

Argument is explicitly typed as `any`

Error message

Argument is explicitly typed as `any`

What it means

Third diagnostic of typescript/explicit-module-boundary-types: a boundary parameter explicitly typed as `any` is reported unless allowArgumentsExplicitlyTypedAsAny is true (default false). The help text recommends `unknown` plus narrowing, because `any` opts out of type checking exactly where the contract matters most.

Source

Thrown at crates/oxc_linter/src/rules/typescript/explicit_module_boundary_types.rs:39

    AstNode,
    context::LintContext,
    rule::{DefaultRuleConfig, Rule},
};

fn func_missing_return_type(fn_span: Span) -> OxcDiagnostic {
    OxcDiagnostic::warn("Missing return type on function")
        .with_help("Define an explicit return type for the function.")
        .with_label(fn_span)
}

fn func_missing_argument_type(param_span: Span) -> OxcDiagnostic {
    OxcDiagnostic::warn("Missing argument type on function")
        .with_help("Define an explicit argument type for each argument.")
        .with_label(param_span)
}

fn func_argument_is_explicitly_any(param_span: Span) -> OxcDiagnostic {
    OxcDiagnostic::warn("Argument is explicitly typed as `any`")
        .with_help(
            "Avoid explicit `any` at module boundaries; prefer `unknown` and narrow before use.",
        )
        .with_label(param_span)
}

#[derive(Debug, Default, Clone, Deserialize)]
pub struct ExplicitModuleBoundaryTypes(Box<ExplicitModuleBoundaryTypesConfig>);

impl Deref for ExplicitModuleBoundaryTypes {
    type Target = ExplicitModuleBoundaryTypesConfig;

    fn deref(&self) -> &Self::Target {
        &self.0
    }
}

#[derive(Debug, Clone, Deserialize, JsonSchema, PartialEq, Eq)]

View on GitHub (pinned to e1e7af627c)

Solutions

  1. Change `any` to `unknown` and narrow inside: `if (typeof x === 'string') { ... }`
  2. Model the real shape with an interface instead of `any`
  3. During migration, set "allowArgumentsExplicitlyTypedAsAny": true and remove it once the edges are typed

Example fix

// before
export function printLength(value: any) {
  console.log(value.length);
}

// after
export function printLength(value: unknown) {
  if (typeof value === 'string') {
    console.log(value.length);
  }
}
Defensive patterns

Strategy: type-guard

Validate before calling

// Gate before merge: keep the rule strict in CI
// .oxlintrc.json
{
  "rules": {
    "typescript/explicit-module-boundary-types": "warn"
  }
}

Type guard

function isRecord(v: unknown): v is Record<string, unknown> {
  return typeof v === 'object' && v !== null;
}

// narrow `unknown` at the boundary instead of accepting `any`
export function handle(payload: unknown): void {
  if (isRecord(payload) && typeof payload.id === 'string') {
    console.log(payload.id);
  }
}

Prevention

When it happens

Trigger: `export function handle(event: any) { ... }` or a public method with an `any` parameter while allowArgumentsExplicitlyTypedAsAny is unset/false; the parameter's type annotation is TSAnyKeyword.

Common situations: Wrapping untyped third-party callbacks (DOM events, JSON payloads) at module edges; gradual TS migrations that sprinkled `any` on parameters; enabling noImplicitAny-style strictness after the fact.

Related errors


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