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 ruleP2stack specificStack: typescript
typescripteventstype-safetydom
Type event-name parameters with keyof WindowEventMap
Constrain event-name arguments to keyof WindowEventMap (optionally unioned with known custom keys) instead of plain string.
PR: hegnar-forum-web · org-mining-hist-2026-06Created: Jun 20, 2026
Bad example
Old codetypescript
| 1 | function useEvent(event: string, cb: () => void) { /* ... */ } |
Explanation (EN)
Objašnjenje (HR)
Good example
New codetypescript
| 1 | type CustomEventKeys = 'app:ready'; |
| 2 | function useEvent(event: keyof WindowEventMap | CustomEventKeys, cb: () => void) { /* ... */ } |
Explanation (EN)
Objašnjenje (HR)