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 ruleP2universalStack: TypeScript
typescriptpropsapi-designclean-code
Prefer optional props over an explicit `| undefined` union
Mark props that may be absent as optional (`name?: T`) instead of typing them `name: T | undefined`, so callers can simply omit them.
PR: hegnar-components · org-mining-hist-2026-06Created: Jun 18, 2026
Bad example
Old codetypescript
| 1 | interface Props { |
| 2 | text: string | undefined; |
| 3 | placeholder: string | undefined; |
| 4 | } |
Explanation (EN)
Objašnjenje (HR)
Good example
New codetypescript
| 1 | interface Props { |
| 2 | text?: string; |
| 3 | placeholder?: string; |
| 4 | } |
| 5 | // undefined values then simply aren't passed as props |
Explanation (EN)
Objašnjenje (HR)