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
eventstypescripttypesdom
Type the detail payload of dispatched custom events
Give CustomEvent detail payloads an explicit type rather than leaving them untyped or Record<string, unknown> when the shape is known.
PR: hegnar-forum-web · org-mining-hist-2026-06Created: Jun 20, 2026
Bad example
Old codetypescript
| 1 | const dispatch = (detail?: Record<string, unknown>) => { |
| 2 | window.dispatchEvent(new CustomEvent('openModal', { detail })); |
| 3 | }; |
Explanation (EN)
Objašnjenje (HR)
Good example
New codetypescript
| 1 | type OpenModalDetail = { action: 'start' | 'edit'; data: ModalData }; |
| 2 | const dispatch = (detail: OpenModalDetail) => { |
| 3 | window.dispatchEvent(new CustomEvent<OpenModalDetail>('openModal', { detail })); |
| 4 | }; |
Explanation (EN)
Objašnjenje (HR)