oxc-project/oxc · error · OxcDiagnostic

Missing type parameters on mock function call

Error message

Missing type parameters on mock function call

What it means

Emitted by the vitest/require-mock-type-parameters rule at a mock function creation or call (`vi.fn()`, mocked methods, etc.) that omits its generic type parameters. Without type parameters the mock's signature is untyped, losing type safety and editor support; the rule requires the expected types to be spelled out.

Source

Thrown at crates/oxc_linter/src/rules/vitest/require_mock_type_parameters.rs:23

    AstKind,
    ast::{CallExpression, ChainElement, Expression},
};
use oxc_diagnostics::OxcDiagnostic;
use oxc_macros::declare_oxc_lint;
use oxc_span::Span;
use oxc_str::CompactStr;

use crate::{
    context::LintContext,
    rule::{DefaultRuleConfig, Rule},
    rules::PossibleJestNode,
    utils::{
        JestFnKind, JestGeneralFnKind, KnownMemberExpressionProperty, parse_general_jest_fn_call,
    },
};

fn require_mock_type_parameters_diagnostic(span: Span, method_name: &str) -> OxcDiagnostic {
    OxcDiagnostic::warn("Missing type parameters on mock function call")
        .with_help(format!(
            "Add a type parameter to the mock function, e.g. `vi.{method_name}<() => void>()`."
        ))
        .with_label(span)
}

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

#[derive(Debug, Default, Deserialize, Clone, JsonSchema)]
#[serde(rename_all = "camelCase", default, deny_unknown_fields)]
pub struct RequireMockTypeParametersConfig {
    /// Also require type parameters for `importActual` and `importMock`.
    check_import_functions: bool,
}

impl std::ops::Deref for RequireMockTypeParameters {
    type Target = RequireMockTypeParametersConfig;

View on GitHub (pinned to e1e7af627c)

Solutions

  1. Add type parameters to the mock call, e.g. `vi.fn<(a: string) => number>()`
  2. Type the mock against the real function type it stands in for
Defensive patterns

Strategy: type-guard

When it happens

Trigger: Thrown at crates/oxc_linter/src/rules/vitest/require_mock_type_parameters.rs:23 when the library encounters an invalid state.

Common situations: See trigger scenarios.


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