skills/typescript-expert/SKILL.md
Resolves TypeScript and JavaScript problems across type-level programming, performance, monorepo management, migration, and modern tooling. Invoke when diagnosing "type instantiation excessively deep" errors, migrating JS to TS, configuring strict tsconfig, debugging module resolution, or choosing between Biome/ESLint/Turborepo/Nx.
npx skillsauth add shipshitdev/library typescript-expertInstall this skill globally with one command. Works with Claude Code, Cursor, and Windsurf.
3 of 9 scanners reported clean
Some scanners were skipped, did not run, or reported a non-clean status. Review each row below.
Analyze project setup comprehensively:
Prefer built-in file-reading and search capabilities for performance. Shell commands are fallbacks.
# Core versions and configuration
bunx 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:
Identify the specific problem category and complexity level
Apply the appropriate solution strategy from the expertise below
Validate thoroughly:
# Fast fail approach (avoid long-lived processes)
bun run typecheck || bunx tsc --noEmit
bun run test || bunx vitest run --reporter=basic --no-watch
# Only if needed and build affects outputs/config
bun run build
Safety note: Avoid watch/serve processes in validation. Use one-shot diagnostics only.
Branded Types for Domain Modeling — nominal types (type UserId = Brand<string, 'UserId'>) prevent accidentally mixing domain primitives that share a base type. Use for critical domain primitives, API boundaries, currency/units. See references/typescript-cheatsheet.md (§ Branded Types) for the full pattern. Resource: https://egghead.io/blog/using-branded-types-in-typescript
Advanced Conditional Types — recursive type manipulation (e.g. DeepReadonly<T>) and template-literal event-source APIs. Use for library APIs, type-safe event systems, compile-time validation. Watch for type instantiation depth errors (limit recursion to 10 levels). See references/typescript-cheatsheet.md (§ Conditional Types, § Mapped Types, § Template Literal Types).
Type Inference Techniques — use satisfies (TS 5.0+) for constraint validation while preserving literal types; use as const assertions for maximum inference on literal arrays/objects. See references/typescript-cheatsheet.md (§ Best Practices).
Type Checking Performance
bunx tsc --extendedDiagnostics --incremental false | grep -E "Check time|Files:|Lines:|Nodes:"
Common fixes for "Type instantiation is excessively deep": replace type intersections with interfaces, split large union types (>100 members), avoid circular generic constraints, use type aliases to break recursion.
Build Performance Patterns
skipLibCheck: true for library type checking only (often significantly improves performance on large projects, but avoid masking app typing issues)incremental: true with .tsbuildinfo cacheinclude/exclude preciselycomposite: true"The inferred type of X cannot be named"
ReturnType<typeof function> helper; break circular dependencies with type-only importsMissing type declarations — add an ambient .d.ts module declaration for untyped packages. See references/typescript-cheatsheet.md (§ Module Declarations). For more detail: Declaration Files Guide
"Excessive stack depth comparing types"
interface extends instead of type intersection; 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 the file existing:
moduleResolution matches your bundlerbaseUrl and paths alignmentworkspace:*)rm -rf node_modules/.cache .tsbuildinfoPath Mapping at Runtime — TypeScript paths only work at compile time, not runtime:
ts-node -r tsconfig-paths/registerJavaScript to TypeScript Migration — incremental strategy: enable allowJs/checkJs in the existing tsconfig, rename files gradually (.js → .ts), add types file by file, enable strict mode features one by one. See references/full-guide.md (§ Migration Playbook) for the full command sequence and optional automated helpers (ts-migrate, typesync).
Tool 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) |
Nx vs Turborepo Decision Matrix
TypeScript Monorepo Configuration — root tsconfig references array plus composite/declaration/declarationMap per package. See references/full-guide.md (§ Monorepo TypeScript Configuration) for the full config.
Use Biome when: speed is critical, want a single tool for lint + format, TypeScript-first project, okay with 64 TS rules vs 100+ in typescript-eslint.
Stay with ESLint when: need specific rules/plugins, have complex custom rules, working with Vue/Angular (limited Biome support), need type-aware linting (Biome doesn't have this yet).
Vitest Type Testing (Recommended) — write .test-d.ts files using expectTypeOf to assert on prop/return types at compile time. See references/full-guide.md (§ Vitest Type Testing) for a full example.
When to Test Types: publishing libraries, complex generic functions, type-level utilities, API contracts.
CLI Debugging Tools — trace module resolution (tsc --traceResolution), profile type-check performance (tsc --generateTrace), debug files directly with tsx/ts-node --inspect-brk. See references/full-guide.md (§ CLI Debugging Tools) for the full command set.
Custom Error Classes — extend Error, set this.name, and call Error.captureStackTrace to preserve the stack. See references/full-guide.md (§ Custom Error Classes) for the full pattern.
Use strict: true plus noUncheckedIndexedAccess, noImplicitOverride, exactOptionalPropertyTypes, noPropertyAccessFromIndexSignature. See references/tsconfig-strict.json for a full production-ready strict config.
"type": "module" in package.json.mts for TypeScript ESM files if needed"moduleResolution": "bundler" for modern toolsconst pkg = await import('cjs-package')
await import() requires async function or top-level await in ESM(await import('pkg')).default depending on the package's export structure and compiler settingsany types (use unknown or proper types)as) justified and minimalinterface over type for object shapes (better error messages)skipLibCheck: true in tsconfignever type"Which tool should I use?"
Type checking only? → tsc
Type checking + linting speed critical? → Biome
Type checking + comprehensive linting? → ESLint + typescript-eslint
Type testing? → Vitest expectTypeOf
Build tool? → Project size <10 packages? Turborepo. Else? Nx
"How do I fix this performance issue?"
Slow type checking? → skipLibCheck, incremental, project references
Slow builds? → Check bundler config, enable caching
Slow tests? → Vitest with threads, avoid type checking in tests
Slow language server? → Exclude node_modules, limit files in tsconfig
Always validate changes don't break existing functionality before considering the issue resolved.
development
TypeScript refactoring and modernization guidelines from a principal specialist perspective. This skill should be used when refactoring, reviewing, or modernizing TypeScript code to ensure type safety, compiler performance, and idiomatic patterns. Triggers on tasks involving TypeScript type architecture, narrowing, generics, error handling, or migration to modern TypeScript features.
tools
Turborepo monorepo build system guidance. Triggers on: `turbo.json`, task pipelines, `dependsOn`, caching, remote cache, the `turbo` CLI, `--filter`, `--affected`, CI optimization, environment variables, internal packages, monorepo structure, and package boundaries. Use when the user configures tasks or workflows, creates packages, sets up a monorepo, shares code between apps, runs changed packages, debugs cache behavior, or works in an `apps/` plus `packages/` workspace.
tools
Provides Tailwind CSS v4 performance optimization and best practices guidelines. Triggers when writing, reviewing, or refactoring Tailwind CSS v4 code; when working with Tailwind configuration, @theme directive, utility classes, responsive design, dark mode, container queries, or CSS generation optimization.
testing
Reports portable validation evidence when checking a fixture skill.