oxc-project/oxc · error · OxcDiagnostic

Property {parameter} should be declared as a parameter prope

Error message

Property {parameter} should be declared as a parameter property.

What it means

Raised by typescript/parameter_properties when configured to prefer parameter properties and a constructor explicitly declares-then-assigns a member that could be a parameter property (`this.foo = foo` with `foo` a constructor param). At the throw site the boilerplate member declaration duplicates what TypeScript's parameter-property shorthand (`constructor(private foo: string)`) expresses in one place. prefer_parameter_property_diagnostic fires from check_prefer_parameter_property for each such redundant assignment.

Source

Thrown at crates/oxc_linter/src/rules/typescript/parameter_properties.rs:31

use oxc_diagnostics::OxcDiagnostic;
use oxc_macros::declare_oxc_lint;
use oxc_span::{GetSpan, Span};
use oxc_str::Str;

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

fn prefer_class_property_diagnostic(parameter: &str, span: Span) -> OxcDiagnostic {
    OxcDiagnostic::warn(format!("Property {parameter} should be declared as a class property."))
        .with_help("Remove the parameter modifier and declare this member on the class instead.")
        .with_label(span)
}

fn prefer_parameter_property_diagnostic(parameter: &str, span: Span) -> OxcDiagnostic {
    OxcDiagnostic::warn(format!("Property {parameter} should be declared as a parameter property."))
        .with_help("Declare this member as a constructor parameter property and remove the class field plus assignment.")
        .with_label(span)
}

#[derive(Debug, Default, Clone, Copy, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
#[serde(rename_all = "kebab-case")]
enum Prefer {
    #[default]
    ClassProperty,
    ParameterProperty,
}

#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
enum Modifier {
    #[serde(rename = "private")]
    Private,
    #[serde(rename = "private readonly")]
    PrivateReadonly,

View on GitHub (pinned to e1e7af627c)

Solutions

  1. Replace the field plus constructor assignment with a parameter property: constructor(private x: number).
  2. Change the rule preference to 'class-property' if that style is desired.
Defensive patterns

Strategy: validation

When it happens

Trigger: Thrown at crates/oxc_linter/src/rules/typescript/parameter_properties.rs:31 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/de6a8102472da0ad. Report an issue: GitHub.