typescript-javascript
Skill17 starsChanged 55 days agoMITView on GitHub
TypeScript and JavaScript development standards for modern web and Node.js development. Covers strict TypeScript configuration, type safety patterns, ESM modules, async/await, testing with Jest/Vitest, and security best practices. Use when working with .ts, .tsx, .js, .mjs files, package.json, tsconfig.json, or when asking about TypeScript/JavaScript best practices.
In this repository53 other files it gives its agents.
- agents-sdkSkill
- agent-workflowSkill
- api-designSkill
- aws-iamSkill
- bash-shell-scriptingSkill
- cicd-github-actionsSkill
- cloudflare-email-serviceSkill
- cloudflareSkill
- cloudflare-waf-authorSkill
- cloudflare-workers-authorSkill
- cloud-platformsSkill
- codebase-security-auditSkill
- containers-orchestrationSkill
- core-engineeringSkill
- database-postgresqlSkill
- databricksSkill
- data-engineeringSkill
- distributed-transactionsSkill
- documentation-standardsSkill
- domain-driven-designSkill
- durable-objectsSkill
- frontend-engineeringSkill
- git-workflowSkill
- go-rust-systemsSkill
- iam-security-advisorSkill
- independent-verificationSkill
- infrastructure-iacSkill
- kubernetes-containersSkill
- kubernetes-operator-developmentSkill
- mcp-developmentSkill
- memory-architectureSkill
- multi-perspective-reviewSkill
- networking-transportSkill
- observabilitySkill
- oktaSkill
- pdf-exportSkill
- python-developmentSkill
- reactflow-architecture-diagramsSkill
- sandbox-sdkSkill
- scripting-automationSkill
- security-testingSkill
- service-resilienceSkill
- single-file-dashboardSkill
- skills-compositionSkill
- skills-continuous-improvementSkill
- snowflakeSkill
- system-designSkill
- web-perfSkill
- web-research-kb-refreshSkill
- workers-best-practicesSkill
- workload-identitySkill
- wranglerSkill
- zero-trustSkill
The file
We split this skill into the rules it gives an agent
12 rules. About 0 are common, 5 are distinctive, and 7 are very specific to this project.
≈0
Common · estimate
Many files like this have a rule of this kind.
≈5
Distinctive · estimate
This author's own choices. Worth a look.
7
Very specific
Tied to their project's names, files or tools. Probably skip.
- Common
- Distinctive
- Very specific
- Distinctive: line 13
Explicit Over Implicit: Prefer explicit types for clarity and maintainability
- Very specific: line 15
Security First: Never use eval, sanitize HTML, validate inputs
- Very specific: line 42
Every service/network fetch must include a timeout, check response.ok, and validate the JSON shape before returning typed data.
- Very specific: line 68
Use the observability skill (${HANDBOOK_ROOT}/skills/observability/SKILL.md) for event schemas, redaction, metric cardinality, trace …
- Distinctive: line 71
Keep runtime-specific logger and OpenTelemetry integration in this skill.
- Distinctive: line 90
Add TSDoc or JSDoc when callers need behavior, error, ownership, blocking, side-effect, constraint, or lifecycle information that the …
- Very specific: line 91
Use @param, @returns, @throws, @remarks, and examples only when they add contract information.
- Distinctive: line 92
Do not add comments that merely repeat names or types.
- Very specific: line 229
Never use eval, new Function, or unsanitized innerHTML
- Very specific: line 230
Use textContent for DOM insertion
- Very specific: line 232
Do not log secrets/tokens/PII
- Distinctive: line 233
Use parameterized queries.
≈ “Common” is an estimate: at least 1 in 5 of the 350,495 skill files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.
Files
TypeScript & JavaScript Development
Mandatory gates are owned by the JavaScript and TypeScript rule (${HANDBOOK_ROOT}/rules/225-javascript-typescript.mdc). This skill and its references own procedures and examples.
Guiding Principles
- Type Safety: Leverage strict mode, avoid
any, use discriminated unions - Explicit Over Implicit: Prefer explicit types for clarity and maintainability
- Modern Defaults: ESM, const/let, async/await, optional chaining
- Security First: Never use
eval, sanitize HTML, validate inputs
Quick Reference
| Aspect | TypeScript | JavaScript |
| Package Manager | pnpm preferred | pnpm preferred |
| Module System | ES Modules | ES Modules + // @ts-check |
| Linting | eslint --max-warnings=0 | eslint --max-warnings=0 |
| Formatting | Prettier | Prettier |
| Types | Strict mode | JSDoc types |
Non-Negotiables
NN-1: Validate at trust boundaries
Static types do not validate runtime data. Treat HTTP bodies, responses, webhooks, queue messages, localStorage/sessionStorage, environment variables, CLI args, and JSON files as unknown until validated with Zod or an explicit type guard.
Reject:
JSON.parse(raw) as Tawait response.json() as T- unchecked property access on remote JSON
as anyor double assertions (value as unknown as T)
NN-2: Fetch/API calls require timeout + status check + schema validation
Every service/network fetch must include a timeout, check response.ok, and validate the JSON shape before returning typed data.
import { z } from 'zod';
async function fetchJson<T>(
url: string,
schema: z.ZodType<T>,
options: RequestInit = {},
): Promise<T> {
const response = await fetch(url, {
...options,
signal: options.signal ?? AbortSignal.timeout(5_000),
headers: { Accept: 'application/json', ...options.headers },
});
if (!response.ok) {
throw new Error(`request failed: HTTP ${response.status}`);
}
return schema.parse(await response.json());
}NN-3: Production servers are hardened by default
Node/Express/Fastify services need bounded request bodies, explicit CORS, security headers, request IDs, structured logging, generic 5xx responses, and graceful shutdown. Do not use direct app.listen(...) examples for production services without retaining and closing the server.
Use the observability skill
(${HANDBOOK_ROOT}/skills/observability/SKILL.md) for event schemas, redaction,
metric cardinality, trace propagation, SLOs, alerts, and telemetry pipelines.
Keep runtime-specific logger and OpenTelemetry integration in this skill.
NN-4: Package manager and runtime are pinned
Declare packageManager and Node engine policy in package.json; CI uses Corepack and the declared package manager.
Production applications normally use the newest supported active LTS Node.js line accepted by the deployment target. Pin the exact package manager and tested CI runtime, commit one native lockfile, and test compiler upgrades. Follow the dependency and toolchain currency workflow (${HANDBOOK_ROOT}/skills/core-engineering/references/dependency-and-toolchain-currency.md).
{
"packageManager": "pnpm@10.0.0",
"engines": { "node": ">=22" }
}NN-5: Exported APIs have explicit type and documentation contracts
- Production JavaScript uses
// @ts-checkand precise JSDoc types for exported parameters, return values, callbacks, generics, and shared object shapes. - TypeScript exported functions and public methods use explicit parameter and return types. Keep type inference for obvious local variables.
- Add TSDoc or JSDoc when callers need behavior, error, ownership, blocking, side-effect, constraint, or lifecycle information that the signature cannot express.
- Use
@param,@returns,@throws,@remarks, and examples only when they add contract information. - Do not add comments that merely repeat names or types.
- Static types and documentation never replace runtime validation at trust boundaries.
Critical Patterns
// 1. Use strict equality
if (value === 0) { } // ✅ GOOD
if (value == 0) { } // ❌ BAD
// 2. Handle Promise rejections
fetchData().catch(err => console.error(err)); // ✅ GOOD
// 3. Optional chaining and nullish coalescing
const name = user?.profile?.name ?? 'Guest'; // ✅ GOOD
// 4. Use Set/Map for lookups
const seen = new Set(); // ✅ GOOD (O(1))
const seen = []; // ❌ BAD (O(n))
// 5. Never use eval or new Function
eval(userInput); // ❌ NEVER DO THIS
// 6. Sanitize HTML
element.textContent = userInput; // ✅ GOOD
element.innerHTML = userInput; // ❌ BAD (XSS)TypeScript Configuration
{
"compilerOptions": {
"target": "ES2022",
"module": "ESNext",
"moduleResolution": "bundler",
"strict": true,
"noImplicitAny": true,
"strictNullChecks": true,
"noUnusedLocals": true,
"noUnusedParameters": true,
"noUncheckedIndexedAccess": true,
"esModuleInterop": true,
"skipLibCheck": false
}
}Avoid any - Use Proper Types
// ❌ BAD - Loses all type safety
function processData(data: any): any {
return data.value;
}
// ✅ GOOD - Generic type
function processData<T>(data: T): T {
return data;
}
// ✅ GOOD - Unknown for truly unknown types
function processData(data: unknown): string {
if (typeof data === 'object' && data !== null && 'value' in data) {
return String((data as { value: unknown }).value);
}
throw new Error('Invalid data');
}Discriminated Unions
type SuccessResponse = {
status: 'success';
data: { id: string; name: string };
};
type ErrorResponse = {
status: 'error';
error: { code: number; message: string };
};
type ApiResponse = SuccessResponse | ErrorResponse;
function handleResponse(response: ApiResponse): void {
if (response.status === 'success') {
console.log(response.data.id); // Type-safe
} else {
console.log(response.error.message); // Type-safe
}
}Utility Types
interface User {
id: string;
name: string;
email: string;
password: string;
}
type UserUpdate = Partial<User>; // All optional
type UserCredentials = Pick<User, 'email' | 'password'>;
type UserPublic = Omit<User, 'password'>; // Exclude password
type RequiredUser = Required<User>; // All required
type ReadonlyUser = Readonly<User>; // ImmutableAsync Patterns
// Parallel execution
const [users, products] = await Promise.all([
fetchUsers(),
fetchProducts()
]);
// Handle partial failures
const results = await Promise.allSettled([
fetchUsers(),
fetchProducts()
]);
results.forEach(result => {
if (result.status === 'fulfilled') {
console.log(result.value);
} else {
console.error(result.reason);
}
});Security Rules (Mandatory)
- Never use
eval,new Function, or unsanitizedinnerHTML - Use
textContentfor DOM insertion - Validate and sanitize all external inputs
- Do not log secrets/tokens/PII
- Use parameterized queries; no string-built queries
- Enforce HTTPS; secure cookies (HttpOnly, SameSite)
Naming Conventions
| Type | Convention | Example |
| Functions/Variables | camelCase | fetchUserData |
| Classes/Interfaces | PascalCase | UserService |
| Constants | UPPER_SNAKE_CASE | MAX_RETRIES |
| Types | PascalCase | ApiResponse |
Detailed References
- TypeScript Patterns: See TypeScript patterns (
${HANDBOOK_ROOT}/skills/typescript-javascript/references/typescript-patterns.md) for advanced types, generics, and mapped types - JavaScript Patterns: See JavaScript patterns (
${HANDBOOK_ROOT}/skills/typescript-javascript/references/javascript-patterns.md) for JSDoc, ESM, and performance
Does it work?
Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.
Reviews can't be read right now.
Your trail
Files you open will collect here, so you can find them again.
Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.
Now do this for your own.
Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.

