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 ruleP1stack specificStack: typescript
typescripttype-assertionsdomtype-safety
Narrow DOM types with instanceof instead of as assertions
Avoid `as` type assertions on DOM lookups; use `instanceof` checks (or the already-correct return type) so TypeScript actually verifies the type at runtime.
PR: hegnar-web · org-mining-hist-2026-06Created: Jun 19, 2026
Bad example
Old codetypescript
| 1 | const el = document.getElementById('skyscraper') as HTMLDivElement; |
| 2 | el.style.width = '100px'; |
Explanation (EN)
Objašnjenje (HR)
Good example
New codetypescript
| 1 | const el = document.getElementById('skyscraper'); |
| 2 | if (el instanceof HTMLDivElement) { |
| 3 | el.style.width = '100px'; |
| 4 | } |
Explanation (EN)
Objašnjenje (HR)