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).
fullstack ruleP2universalStack: TypeScript
typescripttype-guardredundancy
Keep type guards to the minimal distinguishing checks
If two fields always co-occur in the discriminant shape, check only one in the type guard rather than redundantly checking both.
PR: hegnar-forum-web · org-mining-3rd-2026-06Created: Jun 18, 2026
Bad example
Old codets
| 1 | return typeof d === 'object' && d !== null && 'error' in d && 'statusCode' in d; |
Explanation (EN)
Objašnjenje (HR)
Good example
New codets
| 1 | return typeof d === 'object' && d !== null && 'statusCode' in d; // message/error always co-present |
Explanation (EN)
Objašnjenje (HR)