oxc-project/oxc · error · OxcDiagnostic
Prop '{prop_name}' requires default value to be set.
Error message
Prop '{prop_name}' requires default value to be set. What it means
Emitted by check_object_props and check_type_signature in the vue require-default-prop rule when a prop is marked optional (or not required) in the component options or defineProps type signature but has no default value. It is a validation guard: optional props without defaults resolve to undefined, which often hides runtime bugs.
Source
Thrown at crates/oxc_linter/src/rules/vue/require_default_prop.rs:27
use oxc_macros::declare_oxc_lint;
use oxc_span::{GetSpan, Span};
use crate::{
AstNode,
context::LintContext,
frameworks::FrameworkOptions,
rule::Rule,
utils::{
find_property, for_each_define_props_type_signature,
is_vue_component_options_object_excluding_instance,
},
};
const NATIVE_TYPES: [&str; 7] =
["String", "Number", "Boolean", "Function", "Object", "Array", "Symbol"];
fn require_default_prop_diagnostic(span: Span, prop_name: &str) -> OxcDiagnostic {
OxcDiagnostic::warn(format!("Prop '{prop_name}' requires default value to be set."))
.with_label(span)
}
#[derive(Debug, Default, Clone)]
pub struct RequireDefaultProp;
declare_oxc_lint!(
/// ### What it does
///
/// Requires default value to be set for props that are not marked as
/// `required`.
///
/// ### Why is this bad?
///
/// A prop that is neither required nor given a default is implicitly
/// `undefined` when omitted. Forcing a default keeps the component's
/// behavior explicit and avoids `undefined` leaking into the template and
/// logic. `Boolean` props are exempt because they already default toView on GitHub (pinned to e1e7af627c)
Solutions
- Add a default value in the prop definition, e.g. props: { foo: { type: String, default: '' } }
- For type-based defineProps, mark the prop required by omitting the optional '?' so a default is unnecessary
- Use a compiler macro option like withDefaults(defineProps<...>(), { foo: '' }) for type signatures
Defensive patterns
Strategy: validation
When it happens
Trigger: Thrown at crates/oxc_linter/src/rules/vue/require_default_prop.rs:27 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/f1e0c5bd76d77fc6.
Report an issue: GitHub.