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
typescriptgenericstype-safety
Preserve typed results with generics instead of widening to unknown
Instead of typing a shared callback result as `unknown`, parameterize it with a generic so call sites that know the shape keep type safety.
PR: hegnar-forum-web · org-mining-3rd-2026-06Created: Jun 18, 2026
Bad example
Old codets
| 1 | export type ApiCallback = (result: unknown, success: boolean) => void; |
Explanation (EN)
Objašnjenje (HR)
Good example
New codets
| 1 | export type ApiCallback<T = unknown> = (result: T, success: boolean) => void; |
| 2 |
|
| 3 | window.__api<PingResult>('ping', (result, success) => { |
| 4 | if (success) result.loaded; |
| 5 | }); |
Explanation (EN)
Objašnjenje (HR)