Rules Hub
Code Ruleset
Rule priority, scope & exceptions
Use this to align rules with the senior-level structure (P0/P1/P2, scope, exceptions/tradeoffs).
Distinguish optional absence from explicit null
Use optional and nullable types deliberately; combining them is valid when omission and null mean different things.
Bad example
| 1 | type ArticleProps = { |
| 2 | // Ambiguous: Can be undefined (missing prop), null (explicitly no data), or the object. |
| 3 | ticker?: Ticker | null; |
| 4 | }; |
| 5 |
|
| 6 | const getLabel = (ticker?: Ticker | null) => { |
| 7 | if (!ticker) return null; |
| 8 | return ticker.symbol; |
| 9 | }; |
Explanation (EN)
Unexplained missing states make consumers guess which cases are intentional.
Objašnjenje (HR)
Neobjašnjena stanja odsutnosti prisiljavaju potrošače da pogađaju koji su slučajevi namjerni.
Good example
| 1 | type ProfilePatch = { nickname?: string | null }; |
| 2 | // Omitted: leave unchanged. Null: clear. String: replace. |
Explanation (EN)
The three states express a real update contract rather than redundant uncertainty.
Objašnjenje (HR)
Tri stanja predstavljaju stvaran ugovor ažuriranja, a ne suvišnu neodređenost.
Notes (EN)
Model absence, undefined and explicit null according to their actual consumer meaning; eliminate a state only when it is truly redundant.
Exceptions / Tradeoffs (EN)
PATCH payloads often need omitted = unchanged and null = clear. exactOptionalPropertyTypes also distinguishes omission from explicit undefined. Keep all meaningful states.