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
typescripteventspostmessageinterfaces
Give event and message payloads an explicit type instead of using any
Define an interface for postMessage / event .data payloads so the available fields are documented and type-checked rather than accessed off an untyped value.
PR: frontpage-web · org-mining-hist-2026-06Created: Jun 18, 2026
Bad example
Old codetypescript
| 1 | onMessage(e: MessageEvent) { |
| 2 | if (e.data && e.data.message === 'ready') { /* ... */ } |
| 3 | } |
Explanation (EN)
Objašnjenje (HR)
Good example
New codetypescript
| 1 | interface MessageData { message: string; position: string; } |
| 2 | onMessage(e: MessageEvent) { |
| 3 | const data: MessageData = e.data; |
| 4 | if (data && data.message === 'ready') { /* ... */ } |
| 5 | } |
Explanation (EN)
Objašnjenje (HR)