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).
frontend ruleP1universalStack: TypeScript, React
typescriptpropstype-safetyapi-design
Encode mutually-required props in the type, not at runtime
Use discriminated unions so invalid prop combinations (e.g. a close button without an onClose handler) fail to compile rather than being allowed and checked at runtime.
PR: hegnar-zephr-components · org-mining-hist-2026-06Created: Jun 19, 2026
Bad example
Old codetypescript
| 1 | interface Props { |
| 2 | showCloseButton?: boolean; |
| 3 | onClose?: (open: boolean) => void; // can be true without onClose |
| 4 | } |
Explanation (EN)
Objašnjenje (HR)
Good example
New codetypescript
| 1 | type Props = Base & ( |
| 2 | | { showCloseButton: true; onClose: (open: boolean) => void } |
| 3 | | { showCloseButton?: false; onClose?: (open: boolean) => void } |
| 4 | ); |
Explanation (EN)
Objašnjenje (HR)