Rules Hub
Coding Rules Library
← Back to all rules
Rule priority, scope & exceptions
Use this to align rules with the senior-level structure (P0/P1/P2, scope, exceptions/tradeoffs).
backend ruleP2stack specificStack: TypeScript
typescriptoopreadability
Use constructor parameter properties instead of manual field assignment
When a class field is just assigned from a constructor argument, declare it inline with an access modifier on the parameter. It removes the duplicated field declaration + assignment and keeps the class shorter.
PR: profico-org-corpus batch2 (all stacks/products)Created: Jul 26, 2026
Bad example
Old codets
| 1 | class Service { |
| 2 | private params: Params; |
| 3 | constructor(params: Params) { |
| 4 | this.params = params; |
| 5 | } |
| 6 | } |
Explanation (EN)
The field is declared and then assigned separately — three lines for one dependency.
Objašnjenje (HR)
Good example
New codets
| 1 | class Service { |
| 2 | constructor(private readonly params: Params) {} |
| 3 | } |
Explanation (EN)
The access modifier on the parameter declares and assigns the field in one place.
Objašnjenje (HR)