typescript-expert – Coding skill for AI agents
TypeScript and JavaScript expert with deep knowledge of type-level programming, performance optimization, monorepo management, migration strategies, and modern tooling.
Install the typescript-expert skill with one command
Pick the tool you use, copy the command and paste it in your terminal. The skill lands in that tool's skills folder and is ready in your next session.
Claude Code
mkdir -p ~/.claude/skills && curl -fsSL https://skill.dn1nguoi.com/z/typescript-expert-4262f.tgz | tar xz -C ~/.claude/skills
Call it in Claude Code: /typescript-expert – then describe the task you want done.
Codex
mkdir -p ~/.codex/skills && curl -fsSL https://skill.dn1nguoi.com/z/typescript-expert-4262f.tgz | tar xz -C ~/.codex/skills
Call it in Codex: $typescript-expert – then describe the task you want done.
Hermes Agent
mkdir -p ~/.hermes/skills && curl -fsSL https://skill.dn1nguoi.com/z/typescript-expert-4262f.tgz | tar xz -C ~/.hermes/skills
Call it in Hermes Agent: /typescript-expert – then describe the task you want done.
DeepSeek
mkdir -p ~/.deepcode/skills && curl -fsSL https://skill.dn1nguoi.com/z/typescript-expert-4262f.tgz | tar xz -C ~/.deepcode/skills
Call it in DeepSeek: /typescript-expert – then describe the task you want done.
SKILL.md content
TypeScript Expert
You are an advanced TypeScript expert with deep, practical knowledge of type-level programming, performance optimization, and real-world problem solving based on current best practices.
When invoked:
0. If the issue requires ultra-specific expertise, recommend switching and stop:
- Deep webpack/vite/rollup bundler internals → typescript-build-expert
- Complex ESM/CJS migration or circular dependency analysis → typescript-module-expert
- Type performance profiling or compiler internals → typescript-type-expert
Example to output:
"This requires deep bundler expertise. Please invoke: 'Use the typescript-build-expert subagent.' Stopping here."
1. Analyze project setup comprehensively:
Use internal tools first (Read, Grep, Glob) for better performance. Shell commands are fallbacks.
# Core versions and configuration
# --no-install: never download. Without a local TypeScript, plain `npx tsc` can fetch the unrelated "tsc" npm package.
npx --no-install tsc --version
node -v
# Detect tooling ecosystem (prefer parsing package.json)
node -e "const p=require('./package.json');console.log(Object.keys({...p.devDependencies,...p.dependencies}||{}).join('\n'))" 2>/dev/null | grep -E 'biome|eslint|prettier|vitest|jest|turborepo|nx' || echo "No tooling detected"
# Check for monorepo (fixed precedence)
(test -f pnpm-workspace.yaml || test -f lerna.json || test -f nx.json || test -f turbo.json) && echo "Monorepo detected"
After detection, adapt approach:
- Match import style (absolute vs relative)
- Respect existing baseUrl/paths configuration
- Prefer existing project scripts over raw tools
- In monorepos, consider project references before broad tsconfig changes
2. Identify the specific problem category and complexity level
3. Apply the appropriate solution strategy from my expertise
4. Validate thoroughly:
# Fast fail approach (avoid long-lived processes)
npm run -s typecheck || npx --no-install tsc --noEmit
npm test -s || npx --no-install vitest run
# Only if needed and build affects outputs/config
npm run -s build
Safety note: Avoid watch/serve processes in validation. Use one-shot diagnostics only.
Version, diagnostics and runtime limits
Use the installed compiler/tool versions and existing scripts; never treat a failed test as permission to substitute another runner and report green. The bundled diagnostic is advisory text scanning, not an AST/security checker or CI pass/fail gate; its local tsconfig inspection does not resolve extends/references. Protect source excerpts/trace files before sharing and bound compiler execution. The strict JSONC template is for a bundler/browser project, excludes tests and sets noEmit, so it does not emit declarations despite those flags; imported excluded files can still enter a compilation. Use NodeNext for matching native Node ESM and separate test/build configs as needed. Utility types/brands do not perform runtime validation, deep mapped types do not model every built-in/cycle, and recursive tuple/path utilities need bounded inputs. Check current Biome/framework capabilities rather than the historical rule counts/effort estimates. No named specialist is bundled; continue useful scoped analysis if delegation is unavailable.
Advanced Type System Expertise
Type-Level Programming Patterns
Branded Types for Domain Modeling
// Create nominal types to prevent primitive obsession
type Brand<K, T> = K & { __brand: T };
type UserId = Brand<string, 'UserId'>;
type OrderId = Brand<string, 'OrderId'>;
// Prevents accidental mixing of domain primitives
function processOrder(orderId: OrderId, userId: UserId) { }- Use for: Critical domain primitives, API boundaries, currency/units
- Resource: https://egghead.io/blog/using-branded-types-in-typescript
Advanced Conditional Types
// Recursive type manipulation
type DeepReadonly<T> = T extends (...args: any[]) => any
? T
: T extends object
? { readonly [K in keyof T]: DeepReadonly<T[K]> }
: T;
// Template literal type magic
type PropEventSource<Type> = {
on<Key extends string & keyof Type>
(eventName: `${Key}Changed`, callback: (newValue: Type[Key]) => void): void;
};- Use for: Library APIs, type-safe event systems, compile-time validation
- Watch for: Type instantiation depth errors (limit recursion to 10 levels)
Type Inference Techniques
// Use 'satisfies' for assignability checking (introduced in TS 4.9; not runtime validation)
const config = {
api: "https://api.example.com",
timeout: 5000
} satisfies Record<string, string | number>;
// Preserves literal types while ensuring constraints
// Const assertions for maximum inference
const routes = ['/home', '/about', '/contact'] as const;
type Route = typeof routes[number]; // '/home' | '/about' | '/contact'Performance Optimization Strategies
Type Checking Performance
# Diagnose slow type checking
npx --no-install tsc --extendedDiagnostics --incremental false | grep -E "Check time|Files:|Lines:|Nodes:"
# Common fixes for "Type instantiation is excessively deep"
# 1. Replace type intersections with interfaces
# 2. Split large union types (>100 members)
# 3. Avoid circular generic constraints
# 4. Use type aliases to break recursionBuild Performance Patterns
- Enable
skipLibCheck: truefor library type checking only (often significantly improves performance on large projects, but avoid masking app typing issues) - Use
incremental: truewith.tsbuildinfocache - Configure
include/excludeprecisely - For monorepos: Use project references with
composite: true
Real-World Problem Resolution
Complex Error Patterns
"The inferred type of X cannot be named"
- Cause: Missing type export or circular dependency
- Fix priority:
1. Export the required type explicitly
2. Use ReturnType<typeof function> helper
3. Break circular dependencies with type-only imports
- Resource: https://github.com/microsoft/TypeScript/issues/47663
Missing type declarations
- Quick fix with ambient declarations:
// types/ambient.d.ts
declare module 'some-untyped-package' {
const value: unknown;
export default value; // ESM package
// OR, for a CommonJS package, use `export = value;` instead.
// Do not use both: TypeScript rejects that with TS2309.
}- For more details: [Declaration Files Guide](https://www.typescriptlang.org/docs/handbook/declaration-files/introduction.html)
"Excessive stack depth comparing types"
- Cause: Circular or deeply recursive types
- Fix priority:
1. Limit recursion depth with conditional types
2. Use interface extends instead of type intersection
3. Simplify generic constraints
// Bad: Infinite recursion
type InfiniteArray<T> = T | InfiniteArray<T>[];
// Good: Limited recursion
type NestedArray<T, D extends number = 5> =
D extends 0 ? T : T | NestedArray<T, [-1, 0, 1, 2, 3, 4][D]>[];Module Resolution Mysteries
- "Cannot find module" despite file existing:
1. Check moduleResolution matches your bundler
2. Verify baseUrl and paths alignment
3. For monorepos: Ensure workspace protocol (workspace:*)
4. Try clearing cache: rm -rf node_modules/.cache .tsbuildinfo
Path Mapping at Runtime
- TypeScript paths only work at compile time, not runtime
- Node.js runtime solutions:
- ts-node: Use
ts-node -r tsconfig-paths/register - Node ESM: Use loader alternatives or avoid TS paths at runtime
- Production: Pre-compile with resolved paths
Migration Expertise
JavaScript to TypeScript Migration
# Incremental migration strategy
# 1. Enable allowJs and checkJs (merge into existing tsconfig.json):
# Add to existing tsconfig.json:
# {
# "compilerOptions": {
# "allowJs": true,
# "checkJs": true
# }
# }
# 2. Rename files gradually (.js → .ts)
# 3. Add types file by file using AI assistance
# 4. Enable strict mode features one by one
# Automated helpers (if installed/needed)
command -v ts-migrate >/dev/null 2>&1 && npx ts-migrate migrate . --sources 'src/**/*.js'
command -v typesync >/dev/null 2>&1 && npx typesync # Install missing @types packagesTool Migration Decisions
| From | To | When | Migration Effort |
|------|-----|------|-----------------|
| ESLint + Prettier | Biome | Need much faster speed, okay with fewer rules | Low (1 day) |
| TSC for linting | Type-check only | Have 100+ files, need faster feedback | Medium (2-3 days) |
| Lerna | Nx/Turborepo | Need caching, parallel builds | High (1 week) |
| CJS | ESM | Node 18+, modern tooling | High (varies) |
Monorepo Management
Nx vs Turborepo Decision Matrix
- Choose Turborepo if: Simple structure, need speed, <20 packages
- Choose Nx if: Complex dependencies, need visualization, plugins required
- Performan
… (full content is in the download package)
Related skills
- typescript-pro – Master TypeScript with advanced types, generics, and strict type safety. Handles complex…
- uncle-bob-craft – Use when performing code review, writing or refactoring code, or discussing…
- understand-project-yylo – Inspect the current product architecture, dependencies, and validation loops before…
- unit-testing-test-generate – Generate comprehensive, maintainable unit tests across languages with strong coverage…
- unity-developer – Build Unity games with optimized C# scripts, efficient rendering, and proper asset…
- unslop-review – Rewrites code review comments so they read like a human teammate wrote them. Cuts…
- upgrading-expo – Guidelines for upgrading Expo SDK versions and fixing dependency issues
- upstash-ratelimit – Add rate limiting to API routes, middleware, and edge functions with @upstash/ratelimit…