Install with Codex or Claude Copy this prompt, paste it into Codex, Claude, or another assistant, and let it review the skill page and install it for you.
A direct command skips the review prompt. Inspect the source before running it.
Advanced TypeScript patterns and best practices for 2025
user-invocable
false
disable-model-invocation
true
version
1.2.0
updated
2026-06-15
progressive_disclosure
{"entry_point":{"summary":"Type-safe TypeScript patterns with optimal tsconfig, runtime validation, and modern TS 5.2+ features","when_to_use":"When working with TypeScript requiring advanced types, strict configuration, runtime validation, or modern language features (using, decorators)","quick_start":"1. Start with tsconfig baseline 2. Apply core type patterns (const, satisfies) 3. Integrate runtime validation (Zod/TypeBox) 4. Use modern features (using, decorators) as needed"},"references":["advanced-types.md","configuration.md","runtime-validation.md","advanced-patterns-2025.md","decision-trees.md","troubleshooting.md","js-quality-antipatterns.md"]}
TypeScript Core Patterns
Modern TypeScript development patterns for type safety, runtime validation, and optimal configuration.
Quick Start
New Project: Use 2025 tsconfig → Enable strict + noUncheckedIndexedAccess → Choose Zod for validation
Existing Project: Enable strict: false initially → Fix any with unknown → Add noUncheckedIndexedAccess
API Development: Zod schemas at boundaries → z.infer<typeof Schema> for types → satisfies for routes
Library Development: Enable declaration: true → Use const type parameters → See advanced-patterns-2025.md
📐 Advanced Types - Conditional types, mapped types, infer keyword, recursive types. Load when building complex type utilities or generic libraries.
⚙️ Configuration - Complete tsconfig.json guide, project references, monorepo patterns. Load when setting up new projects or optimizing builds.
🔒 Runtime Validation - Zod, TypeBox, Valibot deep patterns, error handling, integration strategies. Load when implementing API validation or form handling.
✨ Advanced Patterns 2025 - TypeScript 5.2+ features: using keyword, stable decorators, import type behavior, satisfies with generics. Load when using modern language features.
🌳 Decision Trees - Clear decision frameworks for type vs interface, generics vs unions, unknown vs any, validation library selection, type narrowing strategies, and module resolution. Load when making TypeScript design decisions.
🔧 Troubleshooting - Common TypeScript errors and fixes, type inference issues, module resolution problems, tsconfig misconfigurations, build performance optimization, and type compatibility errors. Load when debugging TypeScript issues.
JavaScript / Runtime Quality Anti-Patterns
The type system catches type errors, but a class of JavaScript defects is runtime/AST-
level and survives into emitted JS and plain-JS files. Watch for:
Loose equality (==/!=) — coercion bugs and auth flaws; use ===/!== (accept
== null only when commented as "null or undefined").
Dynamic code execution (eval, new Function(str), string setTimeout) — injection
risk and unnecessary; use direct syntax.
Mutating builtins (Object/Array/Function.prototype) — pollutes for…in,
breaks the whole runtime; extend or use free functions instead.
Variable shadowing, var instead of let/const, using functions before
declaration — readability and "wrong variable" bugs.
Logical OR in switch case labels (case 1 || 2: only matches 1) — use stacked
case labels.
Repetitive deep-member access — cache the resolved chain in a local (esp. DOM).
Non-wrapped IIFEs, backslash multiline strings, new Array() — readability
and well-known traps; prefer wrapped IIFEs, template literals, and array literals.
See JS/TS Quality Anti-Patterns for each
defect with compliant/non-compliant examples, severities, false-positive filters, and the
equivalent ESLint/SonarSource rule. Derived from CAST Highlight JavaScript code quality
indicators (https://doc.casthighlight.com/), cross-referenced to ESLint core rules and
SonarSource RSPEC.
Red Flags
Stop and reconsider if:
Using any instead of unknown for external data
Casting with as without runtime validation
Disabling strict mode for convenience
Using @ts-ignore without clear justification
Index access without noUncheckedIndexedAccess
Integration with Other Skills
nextjs-core: Type-safe Server Actions and route handlers
nextjs-v16: Async API patterns and Cache Components typing
mcp-builder: Zod schemas for MCP tool inputs
Related Skills
When using Core, these skills enhance your workflow:
react: TypeScript with React: component typing, hooks, generics
nextjs: TypeScript in Next.js: Server Components, Server Actions typing
drizzle: Type-safe database queries with Drizzle ORM
prisma: Prisma's generated TypeScript types for database schemas
[Full documentation available in these skills if deployed in your bundle]