Rules Hub
Code Ruleset
← Back to all rules
Rule priority, scope & exceptions
Use this to align rules with the senior-level structure (P0/P1/P2, scope, exceptions/tradeoffs).
fullstack ruleP2stack specificStack: typescript
typescripttypesneverunknown
Use unknown[] rather than never[] for an untyped empty array
Give arrays their real element type; unknown[] is for unknown elements and never[] for impossible ones.
PR: hegnar-forum-web · org-mining-hist-2026-06Created: Jun 20, 2026
Bad example
Old codetypescript
| 1 | andRules: [] as never[], |
Explanation (EN)
Asserting never[] for a collection that will receive values contradicts its intended use.
Objašnjenje (HR)
Good example
New codetypescript
| 1 | andRules: [] as unknown[], |
Explanation (EN)
Objašnjenje (HR)
Notes (EN)
Type a mutable collection by its actual element domain; use unknown[] only when elements genuinely have an unknown shape and must be narrowed later.
Exceptions / Tradeoffs (EN)
never[] can legitimately represent an impossible element type or empty-only contract. Replacing it with unknown[] widens the API and may prevent useful typed operations.