typescript-conventionslisted
Install: claude install-skill vinaygiri/fleetmind
# TypeScript / Node.js conventions
Senior defaults. **The project's existing style and lint/tsconfig always win** — read them first and match; this is the baseline when the project is silent.
## Typing
- `strict` on (incl. `strictNullChecks`, `noImplicitAny`). Treat `any` as a smell — prefer `unknown` + narrowing. Justify every `as` cast and non-null `!`; they hide real bugs.
- Model states with **discriminated unions**, not optional-field soup. Make illegal states unrepresentable. `readonly`/`as const` for immutability.
- Exhaustive `switch` with a `never` default so new variants fail to compile. Prefer `type`-only imports (`import type`). Avoid `enum` (use string-literal unions or `as const` objects).
- Public function signatures explicit (params + return); let inference handle locals.
## Null, equality, coercion (the classic JS→TS parity traps)
- Always `===`/`!==`. Beware truthiness on `0`/`""`/`NaN`; check `== null` deliberately only to catch both null and undefined.
- Use `?.` and `??` (not `||`) when `0`/`""`/`false` are valid values. `Number.isNaN`, not `isNaN`. Watch `Date` parsing/timezones.
## Boundaries & errors
- **Validate all external input at the boundary** (request bodies, env, queue messages) with a schema library (e.g. zod); parse into typed data, don't trust `any`.
- Custom `Error` subclasses with a discriminant; never swallow errors silently; don't leak internals/PHI in messages. Consider a `Result<T,E>` for expected failures vs throwing for exception