GuideOpen
TypeScript / JavaScript - Language-Specific Review Notes
Load this file alongside rules/universal.md. Universal rules are not repeated here — only TypeScript/JavaScript-specific rules and idioms.
Front matter
language: typescript
extensions: [".ts", ".tsx", ".js", ".jsx", ".mjs"]TypeScript / JavaScript — Language-Specific Review Notes
Load this file alongside rules/universal.md. Universal rules are not repeated here — only TypeScript/JavaScript-specific rules and idioms.
PR Analyzer — TypeScript / JavaScript Risk Signals
console.log/debuggerstatements left in production code// eslint-disablecomments — verify they are justifiedanytype annotations — require explicit justification@ts-ignore/@ts-expect-error— verify they are justifiedeval()with any dynamic or user-controlled input- Hardcoded API keys or tokens in source
Code Quality — TypeScript / JavaScript Checks
anyused broadly instead of proper typing- Non-null assertion (
!) used without justification vardeclarations — preferconst/let- Missing
awaiton async function calls - Floating promises (no
.catch()and noawait) ==used instead of===
Security
- Flag
innerHTML,outerHTML,document.write()with user-controlled data — usetextContentor a sanitizer - Flag
dangerouslySetInnerHTMLin React without a sanitizer - Flag
eval()/new Function()with dynamic input - Flag JWT decoded without signature verification
- Flag missing
httpOnly/secureflags on cookies
Async / Promises
- Flag floating promises — async calls not
await-ed and without.catch() - Flag
Promise.all()wherePromise.allSettled()is safer (one failure should not cancel siblings) - Flag
asyncfunctions insideforEach—forEachdoes not await; usefor...oforPromise.all() - Flag unhandled promise rejection (no global
unhandledRejectionhandler in Node.js services)
Resource Management
- Flag
fs.createReadStream/fs.createWriteStreamwith nocloseordestroyon error - Flag
EventEmitterlisteners added in a loop without removal — memory leak - Flag
setInterval/setTimeouthandles not cleared when the owning component unmounts or exits - Flag database clients / pools not released after use in Node.js
Exception Handling
- Flag
catch (e) {}(empty catch) — swallowed error - Flag
catch (e)whereeis used asanywithout narrowing — type the error properly - Flag
Promiserejection not handled —.catch()ortry/await/catchrequired - Flag re-throwing a new
Errorwithout wrapping the original — loses stack context - Use
Errorsubclasses for domain errors rather than plain strings or object literals
Performance
- Flag
Array.prototype.find/filter/mapchained multiple times over the same array — combine into one pass - Flag DOM queries (
document.querySelector) inside loops — cache the result - Flag
JSON.parse/JSON.stringifyin a hot path on large objects — consider streaming or partial parsing - Flag
asyncfunctions called sequentially in a loop wherePromise.all()would parallelize them
Idioms and Best Practices
Type Safety (TypeScript)
- Prefer
unknownoveranyfor truly unknown values — forces a type guard before use - Prefer type narrowing (
typeof,instanceof, discriminated unions) over casting - Enable
strictmode intsconfig.json - Prefer
interfacefor object shapes that may be extended;typefor unions and aliases
Modern JavaScript / TypeScript
- Prefer
constby default;letonly when reassignment is needed - Prefer optional chaining (
?.) and nullish coalescing (??) over manual null guards - Prefer
structuredClone()over manual deep-copy patterns - Prefer named exports over default exports for better refactoring support
Null / Undefined Safety
- Distinguish between
null(intentional absence) andundefined(not set) — be consistent - Flag
== nullchecks that accidentally includeundefinedwhen only one is intended
Author: alirezarezvani, Alireza Rezvani skills and agents. License: MIT.
Shown here with formatting for the web. Keep the author and license notice when you reuse it.
Related entries
There are more like this in the members library
The Codex library holds 7,009 entries. Members can search all of them by meaning and read every one in full.