# TypeScript + Node.js Code Review Review {{input}} for code quality, correctness, and best practices. ## TypeScript - Avoid `any`; use explicit return types and enable `strict: true` in tsconfig - Prefer `interface` for object shapes; `type` for unions, intersections, and aliases - Use discriminated unions and utility types (`Partial`, `Readonly`, `Record`, `Pick`) - Avoid unsafe `as` assertions without corresponding runtime validation ## Node.js / Async - No unhandled promise rejections or floating promises - Errors must be caught and handled or propagated — never silently swallowed - Validate all environment variables at startup (not at use-time) - Clean up resources on exit: file handles, DB connections, event listeners, timers, streams ## Reliability - Handle edge cases: null/undefined inputs, empty arrays, zero, NaN, Infinity - Idempotency for retryable operations (DB writes, external API calls) - Graceful shutdown: handle SIGTERM/SIGINT, drain in-flight requests before exiting ## Security - No secrets, tokens, or PII in logs or error messages - Validate and sanitise all external inputs before use - Avoid `eval`, `new Function()`, dynamic `require()`/`import()` with user-controlled values - Parameterise all DB queries — no string interpolation in SQL or query filters - Never return stack traces to API callers ## Code Quality - Each function should do one thing; aim for < 30 lines - `camelCase` for variables/functions; `PascalCase` for types, classes, enums - No dead code, commented-out blocks, or unresolved TODOs - Tests cover the happy path and key failure modes --- List findings as **Critical** (security/data loss/crashes) -> **Major** (bugs/wrong behaviour) -> **Minor** (style/improvements). Cite each location and suggest the concrete fix.