oxc-project/oxc · error · OxcDiagnostic

Expected to return a value in computed property.

Error message

Expected to return a value in computed property.

What it means

Emitted by run of the vue return-in-computed-property rule when a computed getter has a code path that returns no value (checked via definitely_returns_in_all_code_paths_paths helper over the getter context). It is a control-flow guard: a computed that returns undefined on some path produces inconsistent state.

Source

Thrown at crates/oxc_linter/src/rules/vue/return_in_computed_property.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, Serialize};

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

fn return_in_computed_property_diagnostic(span: Span) -> OxcDiagnostic {
    OxcDiagnostic::warn("Expected to return a value in computed property.")
        .with_help("All code paths inside a computed getter must return a value.")
        .with_label(span)
}

#[derive(Debug, Clone, Serialize, Deserialize, JsonSchema)]
#[serde(rename_all = "camelCase", default, deny_unknown_fields)]
struct ReturnInComputedPropertyConfig {
    /// When `true` (default), `return;` (without a value) is treated as a missing return.
    /// Set to `false` to allow bare `return;` as if it returned a value.
    treat_undefined_as_unspecified: bool,
}

impl Default for ReturnInComputedPropertyConfig {
    fn default() -> Self {
        Self { treat_undefined_as_unspecified: true }
    }
}

View on GitHub (pinned to e1e7af627c)

Solutions

  1. Ensure every branch of the computed getter returns a value
  2. Add a default/fallback return at the end of the getter
Defensive patterns

Strategy: validation

When it happens

Trigger: Thrown at crates/oxc_linter/src/rules/vue/return_in_computed_property.rs:16 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/485919ecb5b892c6. Report an issue: GitHub.