| applyTo | {tests,src}/**/*.ts |
|---|---|
| description | TypeScript style rules: explicit types at API boundaries, typed errors, import hygiene, and async conventions. |
- Exported functions/classes MUST have explicit return types (public API clarity).
- Avoid
any. If the type is unknown, useunknownand narrow with type guards before use. - Prefer
readonly/ immutable patterns for inputs (e.g.,readonly T[],Readonly<T>) when mutation is not intended. - Prefer
typefor unions/intersections andinterfacefor object shapes that are expected to be extended (team consistency). - Use
as constfor literal configs and fixtures when it improves inference and prevents widening.
- Library/helpers in
src/MUST throw typed errors (customErrorclasses) with stablenameand meaningful message. - When catching errors, do not swallow: either rethrow, wrap with context, or return a typed
Result-style object. - Tests SHOULD assert on error type/code first; assert exact error messages only when the message is part of the public contract (otherwise tests get brittle).
- Imports MUST be sorted and unused imports removed (keep diffs clean).
- Prefer type-only imports when possible:
import type { X } from '...'(prevents runtime side effects). - Prefer named exports for utilities; avoid default exports unless required by framework conventions.
- Prefer
async/awaitover.then()chains for readability. - Do not introduce hidden side effects at import time (no I/O, no env reads that execute on module load); prefer explicit init functions.
- Waiting and assertion rules are defined in the Playwright instruction files (
e2e-playwright,api-playwright-tests). - Assertions SHOULD be focused: assert one behavior per expectation group and provide a helpful message when it improves debugging.