oxc-project/oxc · error · OxcDiagnostic

Specify type parameter for `{name}` function, otherwise crea

Error message

Specify type parameter for `{name}` function, otherwise created variable will not be typechecked.

What it means

Emitted by run of the vue require-typed-ref rule when ref() or shallowRef() is called without an initial value or an explicit type parameter. Without either, the created variable is typed loosely (null/undefined inferred) and loses type checking on later use.

Source

Thrown at crates/oxc_linter/src/rules/vue/require_typed_ref.rs:12

use oxc_ast::{AstKind, ast::Argument};
use oxc_diagnostics::OxcDiagnostic;
use oxc_macros::declare_oxc_lint;
use oxc_span::Span;

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

fn require_typed_ref_diagnostic(span: Span, name: &str) -> OxcDiagnostic {
    let msg = format!(
        "Specify type parameter for `{name}` function, otherwise created variable will not be typechecked."
    );
    OxcDiagnostic::warn(msg)
        .with_help("Provide an explicit type parameter or an initial value.")
        .with_label(span)
}

#[derive(Debug, Default, Clone)]
pub struct RequireTypedRef;

declare_oxc_lint!(
    /// ### What it does
    ///
    /// Require `ref` and `shallowRef` functions to be strongly typed.
    ///
    /// ### Why is this bad?
    ///
    /// With TypeScript it is easy to prevent usage of `any` by using `noImplicitAny`.
    /// Unfortunately this rule is easily bypassed with Vue `ref()` function.
    /// Calling `ref()` function without a generic parameter or an initial value leads to ref having `Ref<any>` type.
    ///

View on GitHub (pinned to e1e7af627c)

Solutions

  1. Provide an initial value, e.g. ref(0)
  2. Add an explicit type parameter, e.g. ref<string | null>(null)
Defensive patterns

Strategy: type-guard

When it happens

Trigger: Thrown at crates/oxc_linter/src/rules/vue/require_typed_ref.rs:12 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/950fde5ac57fc661. Report an issue: GitHub.