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
typescripttestingtypesany
Confine loose types like any to test code instead of production models
When a test needs to feed deliberately incomplete or malformed data, cast it to a loose type inside the test rather than weakening the production interface to accommodate the unexpected shape.
PR: frontpage-web · org-mining-hist-2026-06Created: Jun 18, 2026
Bad example
Old codetypescript
| 1 | // production model relaxed just so a test can pass |
| 2 | interface ServerData { |
| 3 | structure?: any; |
| 4 | dataSets?: any; |
| 5 | } |
Explanation (EN)
Objašnjenje (HR)
Good example
New codetypescript
| 1 | // production model stays strict |
| 2 | interface ServerData { |
| 3 | structure: Structure; |
| 4 | dataSets: DataSet[]; |
| 5 | } |
| 6 |
|
| 7 | // the test owns the loosening |
| 8 | it('returns [] on broken data', () => { |
| 9 | const broken = {} as any; |
| 10 | expect(parse(broken)).toEqual([]); |
| 11 | }); |
Explanation (EN)
Objašnjenje (HR)