oxc-project/oxc · error · OxcDiagnostic

Assignment of parameter property is unnecessary

Error message

Assignment of parameter property is unnecessary

What it means

Raised by typescript/no-unnecessary-parameter-property-assignment when a constructor body assigns a value to a parameter property that already has that value via its modifier (e.g. constructor(public x = 1) { this.x = 1; }).

Source

Thrown at crates/oxc_linter/src/rules/typescript/no_unnecessary_parameter_property_assignment.rs:19

use oxc_ast::{
    AstKind,
    ast::{
        AssignmentExpression, AssignmentOperator, AssignmentTarget, ClassElement, Expression,
        FormalParameter, Function, MethodDefinitionKind, Statement,
    },
};
use oxc_ast_visit::VisitJs;
use oxc_diagnostics::OxcDiagnostic;
use oxc_macros::declare_oxc_lint;
use oxc_semantic::ScopeFlags;
use oxc_span::Span;
use oxc_str::Str;
use rustc_hash::FxHashSet;

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

fn no_unnecessary_parameter_property_assignment_diagnostic(span: Span) -> OxcDiagnostic {
    OxcDiagnostic::warn("Assignment of parameter property is unnecessary")
        .with_help("Remove the unnecessary assignment")
        .with_label(span)
}

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

declare_oxc_lint!(
    /// ### What it does
    ///
    /// Prevents unnecessary assignment of parameter properties.
    ///
    /// ### Why is this bad?
    ///
    /// Constructor parameters marked with one of the visibility modifiers
    /// public, private, protected, or readonly are automatically initialized.
    /// Providing an explicit assignment is unnecessary and can be removed.
    ///

View on GitHub (pinned to e1e7af627c)

Solutions

  1. Remove the redundant assignment in the constructor body.
  2. Keep the initializer on the parameter property only.
Defensive patterns

Strategy: validation

When it happens

Trigger: Thrown at crates/oxc_linter/src/rules/typescript/no_unnecessary_parameter_property_assignment.rs:19 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/9a1f0bf1988a6ef2. Report an issue: GitHub.