{"record":{"id":"de6a8102472da0ad","repo":"oxc-project/oxc","slug":"property-parameter-should-be-declared-as-a-param","errorCode":null,"errorMessage":"Property {parameter} should be declared as a parameter property.","messagePattern":"Property (.+?) should be declared as a parameter property\\.","errorType":"validation","errorClass":"OxcDiagnostic","httpStatus":null,"severity":"error","filePath":"crates/oxc_linter/src/rules/typescript/parameter_properties.rs","lineNumber":31,"sourceCode":"use oxc_diagnostics::OxcDiagnostic;\nuse oxc_macros::declare_oxc_lint;\nuse oxc_span::{GetSpan, Span};\nuse oxc_str::Str;\n\nuse crate::{\n    AstNode,\n    context::{ContextHost, LintContext},\n    rule::{DefaultRuleConfig, Rule},\n};\n\nfn prefer_class_property_diagnostic(parameter: &str, span: Span) -> OxcDiagnostic {\n    OxcDiagnostic::warn(format!(\"Property {parameter} should be declared as a class property.\"))\n        .with_help(\"Remove the parameter modifier and declare this member on the class instead.\")\n        .with_label(span)\n}\n\nfn prefer_parameter_property_diagnostic(parameter: &str, span: Span) -> OxcDiagnostic {\n    OxcDiagnostic::warn(format!(\"Property {parameter} should be declared as a parameter property.\"))\n        .with_help(\"Declare this member as a constructor parameter property and remove the class field plus assignment.\")\n        .with_label(span)\n}\n\n#[derive(Debug, Default, Clone, Copy, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]\n#[serde(rename_all = \"kebab-case\")]\nenum Prefer {\n    #[default]\n    ClassProperty,\n    ParameterProperty,\n}\n\n#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]\nenum Modifier {\n    #[serde(rename = \"private\")]\n    Private,\n    #[serde(rename = \"private readonly\")]\n    PrivateReadonly,","sourceCodeStart":13,"sourceCodeEnd":49,"githubUrl":"https://github.com/oxc-project/oxc/blob/e1e7af627c8843ab64044ed466b128fcc21a035b/crates/oxc_linter/src/rules/typescript/parameter_properties.rs#L13-L49","documentation":"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.","triggerScenarios":"Thrown at crates/oxc_linter/src/rules/typescript/parameter_properties.rs:31 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Replace the field plus constructor assignment with a parameter property: constructor(private x: number).","Change the rule preference to 'class-property' if that style is desired."],"exampleFix":null,"handlingStrategy":"validation","validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"e1e7af627c8843ab64044ed466b128fcc21a035b","analyzedAt":"2026-08-20T07:01:07.079Z","contentChangedAt":"2026-08-20T07:01:07.079Z","schemaVersion":2},"datasetVersion":"2026-09-14T00:17:10.932Z"}