typescript-best-practices
Audited by Runlayer on Feb 21, 2026
Malicious tool definition detected
Malicious tool definition detected
Malicious tool definition detected
Tool: assets/templates/service-template.ts.md Description: # Service Template Starter template for a TypeScript service class with dependency injection, error handling, and proper types.
Malicious tool definition detected
Tool: assets/tsconfig-presets/recommended.json Description: { "$schema": "https://json.schemastore.org/tsconfig", "_comment": "Balanced TypeScript configuration for most projects", "compilerOptions": { // === Language and Environment === "target": "ES2022", "lib": ["ES2022"], "module": "NodeNext", "moduleResolution": "NodeNext", // === Strict Type Checking === // Core strict mode (recommended minimum) "strict": true, // Additional checks (enable as project matures) "noUncheckedIndexedAccess": fa
Malicious tool definition detected
Tool: assets/tsconfig-presets/strict.json Description: { "$schema": "https://json.schemastore.org/tsconfig", "_comment": "Maximum strictness TypeScript configuration", "compilerOptions": { // === Language and Environment === "target": "ES2022", "lib": ["ES2022"], "module": "NodeNext", "moduleResolution": "NodeNext", // === Strict Type Checking (ALL enabled) === "strict": true, "noImplicitAny": true, "strictNullChecks": true, "strictFunctionTypes": true, "strictBindCallApply": true, "strictProper
Malicious tool definition detected
Tool: references/anti-patterns/common-mistakes.md [1/2] Description: # Common Mistakes Reference Quick reference for the most frequent TypeScript errors.
Malicious tool definition detected
Tool: references/architecture/api-design.md [1/2] Description: # API Design Best practices for designing TypeScript interfaces, function signatures, and module APIs.
Tool: references/architecture/api-design.md [2/2] Description: UserErrorCodes[keyof typeof UserErrorCodes]; interface UserError { code: UserErrorCode; message: string; details?: Record<string, unknown>; } ``` ## Documentation ### JSDoc for Public APIs ```typescript /** * Creates a new user account * * @param options - User creation options * @returns The created user * @throws {ValidationError} If email format is invalid * @throws {DuplicateError} If email already exists * * @example * ```typesc
Malicious tool definition detected
Tool: references/architecture/project-structure.md [1/2] Description: # Project Structure Best practices for organizing TypeScript projects, directory structure, and configuration.
Tool: references/architecture/project-structure.md [2/2] Description: = z.infer<typeof envSchema>; export function loadEnv(): Env { const result = envSchema.safeParse(process.env); if (!result.success) { console.error("Invalid environment variables:"); console.error(result.error.format()); process.exit(1); } return result.data; } // config/index.ts import { loadEnv } from "./env"; const env = loadEnv(); export const config = { env: env.NODE_ENV, port: env.PORT, database: { url: env.DATABASE_URL,
Malicious tool definition detected
Tool: references/patterns/async-patterns.md [1/2]
Tool: references/patterns/async-patterns.md [2/2] Description: Throttling ### Async Debounce ```typescript function debounceAsync<T extends unknown[], R>( fn: (...args: T) => Promise<R>, delayMs: number ): (...args: T) => Promise<R> { let timeoutId: ReturnType<typeof setTimeout> | null = null; let pendingPromise: Promise<R> | null = null; let resolve: ((value: R) => void) | null = null; let reject: ((error: unknown) => void) | null = null; return (...args: T): Promise<R> => { if (timeoutId) { cl
Malicious tool definition detected
Tool: references/patterns/error-handling.md [1/2] Description: # Error Handling Patterns Type-safe error handling in TypeScript using Result types, typed errors, and discriminated unions.
Tool: references/patterns/error-handling.md [2/2] Description: results: Array<Promise<Result<T, E>>> ): Promise<Result<T[], E>> { const settled = await Promise.all(results); const errors: E[] = []; const values: T[] = []; for (const result of settled) { if (result.success) { values.push(result.value); } else { errors.push(result.error); } } if (errors.length > 0) { return err(errors[0]); // Return first error } return ok(values); } // Collect all errors async function collectAllResults<T, E>( re
Malicious tool definition detected
Tool: references/patterns/functional-patterns.md [1/2] Description: # Functional Patterns Functional programming patterns in TypeScript: immutability, pure functions, composition, and higher-order functions.
Tool: references/patterns/functional-patterns.md [2/2] Description: "some"; readonly value: T }; type None = { readonly _tag: "none" }; type Option<T> = Some<T> | None; // Constructors function some<T>(value: T): Option<T> { return { _tag: "some", value }; } function none<T = never>(): Option<T> { return { _tag: "none" }; } // Type guards function isSome<T>(option: Option<T>): option is Some<T> { return option._tag === "some"; } function isNone<T>(option: Option<T>): option is None { return opti
Malicious tool definition detected
Tool: references/patterns/module-patterns.md [1/2] Description: # Module Patterns Best practices for TypeScript module organization, exports, dependency injection, and circular dependency prevention.
Tool: references/patterns/module-patterns.md [2/2] Description: db, cache }); return { db, cache, services }; } // main.ts const app = await init(); ``` ## Type-Only Imports ### Separate Type and Value Imports ```typescript // Import types separately (removed at compile time) import type { User, UserRole } from "./user.ts"; import { createUser, validateUser } from "./user.ts"; // Or use inline type imports import { createUser, type User } from "./user.ts"; ``` ### Type-Only Re-exports ```typescr
Malicious tool definition detected
Tool: references/type-system/advanced-types.md [1/2] Description: # Advanced Types Deep dive into TypeScript's advanced type features: generics, conditional types, mapped types, and template literal types.
Tool: references/type-system/advanced-types.md [2/2] Description: const user = createBuilder<User>() .set("id", "123") .set("name", "John") .set("email", "john@example.com") .build(); ``` ### Deep Readonly ```typescript type DeepReadonly<T> = T extends object ?
Malicious tool definition detected
Tool: references/type-system/type-guards.md [1/2] Description: # Type Guards Type guards narrow types at runtime while maintaining type safety.
Tool: references/type-system/type-guards.md [2/2] Description: "default"; } // Better: explicit null check function getValueSafe(value: string | number | null): string { if (value !== null) { return String(value); } return "default"; } ``` ### Equality Narrowing ```typescript function compare(a: string | number, b: string | boolean): void { if (a === b) { // a and b are both string (the only common type) console.log(a.toUpperCase(), b.toUpperCase()); } } function handleValue(value: string | numb
Malicious tool definition detected
Tool: references/type-system/utility-types.md [1/2] Description: # Utility Types TypeScript provides built-in utility types for common type transformations.
Tool: references/type-system/utility-types.md [2/2] Description: Omit<T, keyof Entity>; type UpdateInput<T extends Entity> = Partial<Omit<T, keyof Entity>>; type CreateUserInput = CreateInput<User>; // { name: string; email: string } type UpdateUserInput = UpdateInput<User>; // { name?: string; email?: string } ``` ### Deep Partial ```typescript type DeepPartial<T> = T extends object ?
Malicious tool definition detected
Tool: scripts/analyze.ts [1/2] Description: #!/usr/bin/env -S deno run --allow-read /** * TypeScript Code Analyzer * * Static analysis for TypeScript code quality issues.
Tool: scripts/analyze.ts [2/2] Description: (before.endsWith("!") || after.startsWith("=")) { continue; } // Check if inside string const beforeQuotes = (before.match(/"/g) || []).length; const beforeSingleQuotes = (before.match(/'/g) || []).length; if (beforeQuotes % 2 === 1 || beforeSingleQuotes % 2 === 1) { continue; } } issues.push({ severity: pattern.severity, category: pattern.category, message: pattern.message, file: filePath, line: lineNum + 1, column: match.index + 1, code: match[0], fi
Malicious tool definition detected
Tool: scripts/generate-types.ts [1/2] Description: #!/usr/bin/env -S deno run --allow-read --allow-write /** * TypeScript Type Generator * * Generate TypeScript types from JSON data or API responses.
Tool: scripts/generate-types.ts [2/2] Description: (inputPath === "-") { return "Data"; } // Extract filename without extension const parts = inputPath.split("/"); const filename = parts[parts.length - 1]; const nameWithoutExt = filename.replace(/\.[^.]+$/, ""); return toPascalCase(nameWithoutExt); } // === Help Text === function printHelp(): void { console.log(` ${SCRIPT_NAME} v${VERSION} - Generate TypeScript types from JSON Usage: deno run --allow-read --allow-write scripts/generate-types.ts
Malicious tool definition detected
Tool: scripts/scaffold-module.ts [1/3] Description: #!/usr/bin/env -S deno run --allow-read --allow-write /** * TypeScript Module Scaffolder * * Create properly structured TypeScript modules with types, * implementation, and optional test files.
Tool: scripts/scaffold-module.ts [2/3] Description: = { ...INITIAL_STATE }; } /** * Get current state */ getState(): Readonly<${pascalName}State> { return this.state; } /** * Activate the component */ activate(): void { this.setState({ isActive: true }); this.emitEvent("activate"); } /** * Deactivate the component */ deactivate(): void { this.setState({ isActive: false }); this.emitEvent("deactivate"); } /** * Set loading state */ setLoading(isLoading: boolean): void { this.setState({ isLoading
Tool: scripts/scaffold-module.ts [3/3] Description: ${hookName}({ initialValue: "initial" }); actions.setValue("changed"); actions.reset(); // Note: Verify reset behavior }); });`; break; } return `/** * Tests for ${pascalName} */ ${importStatement} // Test utilities const describe = (name: string, fn: () => void) => { console.log(\`\ \${name}\`); fn(); }; const it = (name: string, fn: () => void | Promise<void>) => { try { const result = fn(); if (result instanceof Promise) { result.then(() =>