typescript
Skill147 starsChanged 23 days agoMITView on GitHub
This skill should be used when the user asks to "optimize TypeScript performance", "speed up tsc compilation", "configure tsconfig.json", "fix type errors", "improve async patterns", or encounters TS errors (TS2322, TS2339, "is not assignable to"). Also triggers on .ts, .tsx, .d.ts file work involving type definitions, module organization, or memory management. Does NOT cover TypeScript basics, framework-specific patterns, or testing.
Files
TypeScript best practices
Comprehensive performance optimization guide for TypeScript applications. Contains 45 rules across 8 categories, prioritized by impact to guide automated refactoring and code generation.
When to apply
Reference these guidelines when:
- Configuring tsconfig.json for a new or existing project
- Writing complex type definitions or generics
- Optimizing async/await patterns and data fetching
- Organizing modules and managing imports
- Reviewing code for compilation or runtime performance
Rule categories by priority
| Priority | Category | Impact | Prefix |
| 1 | Type System Performance | CRITICAL | type- |
| 2 | Compiler Configuration | CRITICAL | tscfg- |
| 3 | Async Patterns | HIGH | async- |
| 4 | Module Organization | HIGH | module- |
| 5 | Type Safety Patterns | MEDIUM-HIGH | safety- |
| 6 | Memory Management | MEDIUM | mem- |
| 7 | Runtime Optimization | LOW-MEDIUM | runtime- |
| 8 | Advanced Patterns | LOW | advanced- |
Table of contents
- Type System Performance - CRITICAL
- 1.1 Add Explicit Return Types to Exported Functions - CRITICAL (30-50% faster declaration emit)
- 1.2 Avoid Deeply Nested Generic Types - CRITICAL (prevents exponential instantiation cost)
- 1.3 Avoid Large Union Types - CRITICAL (quadratic O(n²) comparison cost)
- 1.4 Extract Conditional Types to Named Aliases - CRITICAL (enables compiler caching, prevents re-evaluation)
- 1.5 Limit Type Recursion Depth - HIGH (prevents exponential type expansion when applicable)
- 1.6 Prefer Interfaces Over Type Intersections - CRITICAL (2-5× faster type resolution)
- 1.7 Simplify Complex Mapped Types - HIGH (reduces type computation by 50-80% when applicable)
- Compiler Configuration - CRITICAL
- 2.1 Configure Include and Exclude Properly - CRITICAL (prevents scanning thousands of unnecessary files)
- 2.2 Enable Incremental Compilation - CRITICAL (50-90% faster rebuilds)
- 2.3 Enable isolatedDeclarations for Parallel Declaration Emit - CRITICAL (enables parallel .d.ts generation without type-checker)
- 2.4 Enable skipLibCheck for Faster Builds - CRITICAL (20-40% faster compilation)
- 2.5 Enable strictFunctionTypes for Faster Variance Checks - CRITICAL (enables optimized variance checking)
- 2.6 Use erasableSyntaxOnly for Node.js Native TypeScript - HIGH (prevents 100% of Node.js type-stripping runtime errors)
- 2.7 Use isolatedModules for Single-File Transpilation - CRITICAL (80-90% faster transpilation with bundlers)
- 2.8 Use Project References for Large Codebases - CRITICAL (60-80% faster incremental builds)
- Async Patterns - HIGH
- 3.1 Annotate Async Function Return Types - HIGH (prevents runtime errors, improves inference)
- 3.2 Avoid await Inside Loops - HIGH (N× faster for N iterations, 10 users = 10× improvement)
- 3.3 Avoid Unnecessary async/await - HIGH (eliminates trivial Promise wrappers and improves stack traces)
- 3.4 Defer await Until Value Is Needed - HIGH (enables implicit parallelization)
- 3.5 Use Promise.all for Independent Operations - HIGH (2-10× improvement in I/O-bound code)
- Module Organization - HIGH
- 4.1 Avoid Barrel File Imports - HIGH (200-800ms import cost, 30-50% larger bundles)
- 4.2 Avoid Circular Dependencies - HIGH (prevents runtime undefined errors and slow compilation)
- 4.3 Control @types Package Inclusion - HIGH (prevents type conflicts and reduces memory usage)
- 4.4 Use Dynamic Imports for Large Modules - HIGH (reduces initial bundle by 30-70%)
- 4.5 Use Type-Only Imports for Types - HIGH (eliminates runtime imports for type information)
- 4.6 Avoid Referencing Index Files in Import Paths - HIGH (prevents redundant imports and ensures cleaner import syntax)
- 4.7 Prefer Relative Imports for Local Directory Files - HIGH (ensures local module encapsulation and clean dependencies)
- 4.8 Use Standard Comments for Internal Developer Notes - HIGH (prevents internal repository warnings from leaking into consumer
.d.tsIntelliSense)
- Type Safety Patterns - MEDIUM-HIGH
- 5.1 Enable noUncheckedIndexedAccess - MEDIUM-HIGH (prevents 100% of unchecked index access errors at compile time)
- 5.2 Enable strictNullChecks - MEDIUM-HIGH (prevents null/undefined runtime errors)
- 5.3 Prefer unknown Over any - MEDIUM-HIGH (forces type narrowing, prevents runtime errors)
- 5.4 Use Assertion Functions for Validation - MEDIUM-HIGH (reduces validation boilerplate by 50-70%)
- 5.5 Use const Assertions for Literal Types - MEDIUM-HIGH (preserves literal types, enables better inference)
- 5.6 Use Exhaustive Checks for Union Types - MEDIUM-HIGH (prevents 100% of missing case errors at compile time)
- 5.7 Use Type Guards for Runtime Type Checking - MEDIUM-HIGH (eliminates type assertions, catches errors at boundaries)
- Memory Management - MEDIUM
- 6.1 Avoid Closure Memory Leaks - MEDIUM (prevents retained references in long-lived callbacks)
- 6.2 Avoid Global State Accumulation - MEDIUM (prevents unbounded memory growth)
- 6.3 Clean Up Event Listeners - MEDIUM (prevents unbounded memory growth)
- 6.4 Clear Timers and Intervals - MEDIUM (prevents callback retention and repeated execution)
- 6.5 Use WeakMap for Object Metadata - MEDIUM (prevents memory leaks, enables automatic cleanup)
- Runtime Optimization - LOW-MEDIUM
- 7.1 Avoid Object Spread in Hot Loops - LOW-MEDIUM (reduces object allocations by N×)
- 7.2 Cache Property Access in Loops - LOW-MEDIUM (reduces property lookups by N× in hot paths)
- 7.3 Prefer Native Array Methods Over Lodash - LOW-MEDIUM (eliminates library overhead, enables tree-shaking)
- 7.4 Use for-of for Simple Iteration - LOW-MEDIUM (reduces iteration boilerplate by 30-50%)
- 7.5 Use Modern String Methods - LOW-MEDIUM (2-5× faster than regex for simple patterns)
- 7.6 Use Set/Map for O(1) Lookups - LOW-MEDIUM (O(n) to O(1) per lookup)
- Advanced Patterns - LOW
- 8.1 Use Branded Types for Typesafe IDs - LOW (prevents mixing incompatible ID types)
- 8.2 Use satisfies for Type Validation with Inference - LOW (prevents property access errors, enables 100% autocomplete accuracy)
- 8.3 Use Template Literal Types for String Patterns - LOW (prevents 100% of string format errors at compile time)
References
Other versions64 projects use a version of this.
Word for word · 0
None found.
Edited · 5
- tazo90/next-openapi-gen★ 19396% same
- PyModel/react-frontend-skills★ 2370% same
- thongdn-it/react-agent-skills★ 589% same
- Aver005/agent-skills★ 296% same
- pproenca/unifi-mcp★ 296% same
Wrote their own version · 59
- lobehub/lobe-chat★ 84ksame name
- lobehub/lobehub★ 84ksame name
- recharts/recharts★ 28ksame name
- ccusage/ccusage★ 19ksame name
- ryoppippi/ccusage★ 19ksame name
- scalar/scalar★ 16ksame name
- prowler-cloud/prowler★ 15ksame name
- microsoft/fast★ 9.7ksame name
- epicenter-md/epicenter★ 4.8ksame name
- EpicenterHQ/epicenter★ 4.8ksame name
49 more not listed
How matches are found. Word for word: the exact same text. Edited: shares passages with this file (“99% same” means 99% of its five-word phrases also appear here; 10% or more counts). Their own version: similar meaning, or, weakest, the same name. We can’t tell which project had it first. Projects are counted among the 200 most-starred candidates, and mentions are links to the repository we found, up to 50 per site, so both counts are a floor.
Used alongsideProjects with it also use rust, drizzle and 10 more.
Other files people use alongside this one.
Files found in the same public projects as a version of this one, more often than they turn up anywhere else. Each project counts once, large collections count for less, and this file's own repository is left out.
MicrosoftSkillrust
Use this guide when working on Rust changes in the FAST monorepo.
Also in 8 projects that use this
leonaaardobSkilldrizzle
Complete Drizzle ORM documentation in markdown format. Use when working with Drizzle ORM - covers schema definition, queries, migrations, database connections (PostgreSQL, MySQL, SQLite), integrations (Neon, Supabase, PlanetScale, Cloudflare D1, Turso), column types, relations, transactions, and framework usage (Next.js, SvelteKit, Astro).
Also in 3 projects that use this
mfang0126Skilldevelopment
Full-stack development workflow skill. Guides the complete cycle from understanding requirements to shipping code via PR with Preview validation.
Also in 3 projects that use this
lambdamechanicSkillpython
Default Python stack for Lambda: uv + Astral tools, typed code, schemas, and Hypothesis.
Also in 8 projects that use this
VercelSkillreact
React renderer for json-render that turns JSON specs into React components. Use when working with @json-render/react, building React UIs from JSON, creating component catalogs, or rendering AI-generated specs.
Also in 8 projects that use this
OpenAISkillnextjs
Next.js App Router expert guidance. Use when building, debugging, or architecting Next.js applications — routing, Server Components, Server Actions, Cache Components, layouts, middleware/proxy, data fetching, rendering strategies, and deployment on Vercel.
Also in 5 projects that use this
In this repository40 other files it gives its agents.
- .agents/AGENTS.mdAGENTS.md
- AGENTS.mdAGENTS.md
- skills/typescript/AGENTS.mdAGENTS.md
- .agents/platforms/copilot-instructions.mdCopilot instructions
- arkenvSkill
- bulletproof-reactSkill
- changesetSkill
- code-reviewSkill
- create-skillSkill
- diagnoseSkill
- docs-writerSkill
- excalidrawSkill
- forward-portSkill
- gh-cliSkill
- grill-meSkill
- grill-with-docsSkill
- groom-issueSkill
- hallmarkSkill
- hexagonal-architectureSkill
- improve-codebase-architectureSkill
- internalize-skillSkill
- jsdocSkill
- modularizeSkill
- next-best-practicesSkill
- nuxtSkill
- pnpmSkill
- point-latest-at-rcSkill
- rename-skillSkill
- setup-matt-pocock-skillsSkill
- sync-mainSkill
- tackle-issueSkill
- tddSkill
- the-hatSkill
- the-voiceSkill
- to-prdSkill
- triageSkill
- turborepoSkill
- write-a-skillSkill
- write-issueSkill
- zoom-outSkill
Does it work?
Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.
No reviews yet
People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.
- It worked
- Partly
- It didn't
Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.
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.

