| name | nodejs-typescript-conventions |
| description | Enforces TypeScript-only source, npm for scripts and deps, ESM import and export defaults, async await over raw then chains, no any types, minimal let usage, private or readonly class fields, functional collection helpers. Do not use for plain JavaScript codebases or non-npm package managers. |
Node.js, JavaScript, and TypeScript conventions
Procedures
When writing or modifying application TypeScript
- Author runtime and shared source strictly in TypeScript.
- Use npm exclusively for installs and script execution (
npm install, npm run build). Do not introduce alternate package managers for those roles.
- When libraries omit types, prefer
@types/<package> where published on DefinitelyTyped; rely on bundled types when shipped (Vitest includes types).
- Before finishing edits, validate type correctness via the project toolchain (
npm run build / tsc / editor diagnostics as applicable).
- Prefer
const bindings; reserve let for genuine reassignment and never declare with var.
- Declare class fields
private, readonly, or both unless a deliberate public surface is mandated by the dependency graph.
- Prefer immutable chain helpers (
filter, map, reduce, find) over manual for / while loops for collection transforms.
- Prefer arrow functions for short pure operations and lexical
this where stylistically consistent with surrounding modules.
- Sequence asynchronous operations with
async / await instead of chaining bare .then trees for primary control flow.
- Ban
any; supply concrete interfaces or type aliases covering inputs and outputs.
- Replace CommonJS imports with ESM syntax (
import / export); disallow require and module.exports in TypeScript modules.
- Export a single default when the module exposes exactly one principal symbol; otherwise use named exports with consistent barrel ergonomics.
Error Handling
- When
async awaits risk unhandled rejection, propagate errors to callers or map them to domain-safe results following service-layer norms.
- When dependency scripts assume another package manager, align documentation and CI to npm-first flows before branching tooling.