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 ruleP1stack specificStack: typescript
typescripttypesnull-safetydto
Mark optional properties with `?` and reflect true nullability in the type
An optional field should use the `?` modifier, and a value that can be null in the data source must include `| null` in its type rather than being typed as a plain non-null value.
PR: hegnar-investor-ws · org-mining-2026-06Created: Jun 17, 2026
Bad example
Old codetypescript
| 1 | @IsOptional() |
| 2 | public search: string; // optional but not marked, and never null typed |
| 3 |
|
| 4 | public deletedAt: string; // column is nullable in DB |
Explanation (EN)
Objašnjenje (HR)
Good example
New codetypescript
| 1 | @IsOptional() |
| 2 | public search?: string; |
| 3 |
|
| 4 | public deletedAt: string | null; |
Explanation (EN)
Objašnjenje (HR)