Rules Hub
Code Ruleset
Rule priority, scope & exceptions
Use this to align rules with the senior-level structure (P0/P1/P2, scope, exceptions/tradeoffs).
Keep type guards to the minimal distinguishing checks
Use minimal discriminants for trusted unions and full validation for unknown input.
Bad example
| 1 | return result.kind === "error" && "error" in result; |
| 2 | // result is already a validated discriminated union |
Explanation (EN)
Repeated correlated checks can be redundant inside a validated closed union.
Objašnjenje (HR)
Good example
| 1 | return result.kind === "error"; |
Explanation (EN)
The validated union guarantees error fields for this literal kind; this is not a validator for arbitrary JSON.
Objašnjenje (HR)
Notes (EN)
Simplify a guard after proving its input is a trusted union and the selected discriminant entails the other required properties.
Exceptions / Tradeoffs (EN)
For unknown/raw data, property presence alone does not validate its value type or other promised fields. Validate the full boundary shape before using minimal internal narrowing.