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 void callbacks from explicit undefined results
Express optional returned values with undefined; do not treat TypeScript void and undefined as interchangeable.
Bad example
| 1 | const fromDate = getStartDateForRange(range) ?? undefined; // helper returns Date | void |
Explanation (EN)
A vague void union hides whether the function intentionally returns undefined.
Objašnjenje (HR)
Good example
| 1 | function getStartDateForRange(range: string): Date | undefined { |
| 2 | if (range === "all") return undefined; |
| 3 | return parseRangeStart(range); |
| 4 | } |
| 5 | const fromDate = getStartDateForRange(range); |
Explanation (EN)
The helper explicitly promises undefined for absence; parseRangeStart must return Date for supported non-all ranges.
Objašnjenje (HR)
Notes (EN)
Use T | undefined for an API that promises a value or absence, and check the actual implementation before removing nullish normalization.
Exceptions / Tradeoffs (EN)
void is not interchangeable with undefined: a callback typed () => void may return a runtime value, and void is not generally assignable to undefined. A null-to-undefined conversion may be observable.