type-optimizer

Reduces TypeScript type instantiation counts using measured optimization patterns.

543|18|Updated Jul 8, 2022
One-click install
npx skills add https://github.com/romeerez/orchid-orm --skill type-optimizer
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: type-optimizer
Source: https://github.com/romeerez/orchid-orm/tree/main/.agents/skills/type-optimizer
Command: npx skills add https://github.com/romeerez/orchid-orm --skill type-optimizer

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

TypeScript projects with heavy generic types can suffer from slow compilation caused by excessive type instantiations. This Skill provides a measured, iterative workflow to reduce Instantiations reported by --extendedDiagnostics without changing runtime behavior.

Core Features & Use Cases

  • Ranked Optimization Catalog: Runs top-type-optims.js to list documented type optimizations sorted by historical mean instantiation savings from type-optim.md.
  • Measured Iteration Workflow: Records a baseline with --extendedDiagnostics, applies one optimization at a time, and keeps only changes that reduce instantiations.
  • Statistics Tracking: Uses update-type-optim-stats.js to record each attempt's instantiation diff into bucketed stats, so future runs prioritize proven optimizations.
  • Use Case: A developer notices slow type-checking in a large TypeScript ORM codebase, runs the optimizer to apply patterns like removing redundant intersections and unused generics, and verifies each change lowers the instantiation count.

Quick Start

Use the type-optimizer skill to reduce TypeScript type instantiations in this project, starting with a baseline extendedDiagnostics measurement.

Frequently Asked Questions about type-optimizer

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I reduce TypeScript type instantiations?

Measure a baseline with tsc --extendedDiagnostics, then apply one optimization at a time such as removing redundant intersections, dropping unused generics, or inferring only needed structure. Re-run diagnostics after each change and keep only edits that lower the Instantiations count.

How to find slow TypeScript types in a large project?

Run the TypeScript compiler with the --extendedDiagnostics flag to see the Instantiations metric, which reflects type-checking workload. High instantiation counts usually come from deeply nested conditional types, repeated indexed access, and large interface inference.

Does type optimization change runtime behavior?

No, the workflow prefers type-only edits and preserves public API behavior unless explicitly allowed. Runtime code is only changed when the task explicitly asks for it, and every attempt is verified against the diagnostics output.

What are common TypeScript type performance patterns?

Documented patterns include returning final shapes directly, naming repeated indexed access, avoiding union-to-intersection for optional fields, remapping keys in one pass, and removing cosmetic simplification mapped types from inputs.

When should I revert a type optimization attempt?

Revert any attempt that produces a negative instantiation diff, meaning the count increased, before trying the next idea. Neutral or worse changes should also be undone unless they improve clarity enough to be explicitly accepted.