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
correctnessreactglobalstype-safety
Do not reference functions that are not defined in scope
Calling a function that has no definition in the component (relying on an external runtime injection) is fragile; define it, type it, or guard its existence explicitly.
PR: hegnar-zephr-components · org-mining-hist-2026-06Created: Jun 19, 2026
Bad example
Old codetsx
| 1 | setEnabled(prev => { |
| 2 | const next = !prev; |
| 3 | handleSaveToggleState?.(next); // never defined in this file |
| 4 | return next; |
| 5 | }); |
Explanation (EN)
Objašnjenje (HR)
Good example
New codetsx
| 1 | // declare the injected global so it is typed and discoverable |
| 2 | declare global { interface Window { handleSaveToggleState?: (v: boolean) => void } } |
| 3 | window.handleSaveToggleState?.(next); |
Explanation (EN)
Objašnjenje (HR)