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).
fullstack ruleP1universalStack: typescript
type-assertionsoxlinttestingmocks
Avoid `as` type assertions; mock or construct a properly typed value instead
Type assertions (`as`, `as unknown as T`) are being linted out; when a test needs a partial context, mock the hook/module boundary with `vi.mocked` or build a real typed value rather than coercing a partial object.
PR: hegnar-web#4698 FCK-3550 Drive ad suppression from the article flagCreated: Sep 7, 2026
Bad example
Old codets
| 1 | <Ctx value={{ res: { locals: { adFree } } } as unknown as IContext}> |
Explanation (EN)
Objašnjenje (HR)
Good example
New codets
| 1 | vi.mock(import('./RequestResponse.ts'), async (o) => ({ ...(await o()), useAdFree: vi.fn() })); |
| 2 | vi.mocked(useAdFree).mockReturnValue(true); |
Explanation (EN)
Objašnjenje (HR)
Notes (EN)
Coercing a partial object hides the mismatch and breaks as soon as the consumer reads another field.