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 ruleP1universalStack: typescript
validationnull-safetyinput-handling
Validate type before transforming or coercing input
When a transform assumes a string (or other type), guard the type first since validators/transformers may run in an order that lets null or non-strings through.
PR: hegnar-mws · org-mining-2026-06Created: Jun 17, 2026
Bad example
Old codetypescript
| 1 | @Transform(({ value }) => (value as string).toUpperCase()) // null.toUpperCase() throws |
Explanation (EN)
Objašnjenje (HR)
Good example
New codetypescript
| 1 | @Transform(({ value }) => (typeof value === 'string' ? value.toUpperCase() : value)) |
Explanation (EN)
Objašnjenje (HR)