| name | strict-typescript |
| description | Use when working with a reference for the repository's strict type rules, explaining forbidden practices and how to correctly handle types and mocking in tests. |
| metadata | {"author":"brychanrobot"} |
Strict TypeScript Rules in JJ View
This document outlines the strict TypeScript rules enforced in the jj-view repository and provides guidance on how to correctly cast types, narrow types, and mock dependencies without resorting to anti-patterns.
Core Rules
The project has strict type-checking enabled ("strict": true in tsconfig.json). To maintain code quality and reliability, the following practices are strictly forbidden:
- NO
any types: The use of any disables type checking and is completely forbidden. Use strict types, or if the type is truly unknown, use unknown.
- NO disabling type checks: You may not disable type checking for a line or block of code.
- Forbidden:
// @ts-ignore
- Forbidden:
// eslint-disable-line (for type-related lint rules)
- Forbidden:
// @ts-expect-error
- NO double casting: You may not bypass the type system by casting to
unknown and then immediately casting to another type.
- Forbidden:
const myVar = foo as unknown as Bar;
How to Handle Types Correctly
When you encounter a situation where the TypeScript compiler is unhappy, you must solve it using proper type-safe methods.