{"record":{"id":"8f54aff70a894f09","repo":"oxc-project/oxc","slug":"property-parameter-should-be-declared-as-a-class","errorCode":null,"errorMessage":"Property {parameter} should be declared as a class property.","messagePattern":"Property (.+?) should be declared as a class property\\.","errorType":"validation","errorClass":"OxcDiagnostic","httpStatus":null,"severity":"error","filePath":"crates/oxc_linter/src/rules/typescript/parameter_properties.rs","lineNumber":25,"sourceCode":"    ast::{\n        AssignmentExpression, AssignmentTarget, Class, ClassElement, Expression, FormalParameter,\n        MethodDefinition, MethodDefinitionKind, PropertyDefinition, PropertyKey, Statement,\n        TSAccessibility,\n    },\n};\nuse 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","sourceCodeStart":7,"sourceCodeEnd":43,"githubUrl":"https://github.com/oxc-project/oxc/blob/e1e7af627c8843ab64044ed466b128fcc21a035b/crates/oxc_linter/src/rules/typescript/parameter_properties.rs#L7-L43","documentation":"Raised by typescript/parameter_properties when the rule is configured to prefer explicit class properties and a constructor parameter property (`constructor(private foo: string)`) is found. At the throw site the shorthand declares AND initializes the member implicitly; the project style requires declaring `foo: string` as a class member and assigning it explicitly, which keeps the class shape visible to readers. prefer_class_property_diagnostic fires from check_prefer_class_property for each parameter carrying an accessibility/readonly modifier.","triggerScenarios":"Thrown at crates/oxc_linter/src/rules/typescript/parameter_properties.rs:25 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Remove the parameter modifier and declare the member as a class property, assigning it in the constructor.","Change the rule preference to 'parameter-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-14T05:17:10.506Z"}