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 ruleP2universalStack: TypeScript
typesapi-designclean-code
Normalize a parameter's type rather than branching on it at runtime
If a function accepts string | string[], normalize to one shape (e.g. always an array via rest/flat) so the body doesn't need union-handling branches.
PR: vinify-backend · org-mining-hist-2026-06Created: Jun 19, 2026
Bad example
Old codetypescript
| 1 | private mapFilter(value: string | string[]): string[] { |
| 2 | const arr = Array.isArray(value) ? value : [value]; |
| 3 | return arr; |
| 4 | } |
Explanation (EN)
Objašnjenje (HR)
Good example
New codetypescript
| 1 | private mapFilter(...values: string[]): string[] { |
| 2 | return values.flat(); |
| 3 | } |
Explanation (EN)
Objašnjenje (HR)