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 ruleP1universalStack: TypeScript
typescripttypescorrectnessnull-handling
Type a lookup that can miss as `T | undefined`
A find/lookup function that may not match should return `T | undefined` (not `T`), forcing callers to handle the miss.
PR: hegnar-components · org-mining-hist-2026-06Created: Jun 18, 2026
Bad example
Old codetypescript
| 1 | function findCategoryById(id: number): Category { |
| 2 | return categories.find(c => c.id === id)!; |
| 3 | } |
Explanation (EN)
Objašnjenje (HR)
Good example
New codetypescript
| 1 | function findCategoryById(id: number): Category | undefined { |
| 2 | return categories.find(c => c.id === id); |
| 3 | } |
Explanation (EN)
Objašnjenje (HR)