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).
fullstack ruleP2universalStack: javascript
coercionbooleantypescriptcorrectness
Only coerce with !! when the target value is actually a boolean
!! converts a value to a boolean, which is fine for boolean props/conditions, but don't apply it when the API expects a non-boolean value (it would discard the real value).
PR: hegnar-web · org-mining-hist-2026-06Created: Jun 19, 2026
Bad example
Old codetypescript
| 1 | // flatpickr's `enable` expects an array of dates, not a boolean |
| 2 | const options = { enable: !!props.enabledDate }; |
Explanation (EN)
Objašnjenje (HR)
Good example
New codetypescript
| 1 | // pass the real value where a boolean isn't expected |
| 2 | const options = { enable: props.enabledDate }; |
| 3 | // use !! only where a boolean is genuinely wanted |
| 4 | const options2 = { clickOpens: !!props.closeOnOutsideClick }; |
Explanation (EN)
Objašnjenje (HR)