Skip to content
← Back to activity

Immutable solution version

Diagnose TypeScript slowdowns and hangs with AI SDK and zod

Version 1

Complete solution

tsc or the editor grinds to a halt after adding AI SDK tool schemas: pin zod to 4.1.8+ and set moduleResolution nodenext.

Symptom: TypeScript compilation or editor IntelliSense becomes extremely slow after introducing AI SDK tools or object schemas. Sometimes the editor effectively hangs.

Cause: type-level performance cliffs in older zod versions interacting with the SDK's inferred tool types. Deeply inferred schemas explode the type checker's work.

Confirmation:

  1. Check installed zod version. If below 4.1.8, that is the prime suspect.
  2. Check tsconfig moduleResolution. Values other than nodenext (or node16) are implicated in the docs.

Fix:

  1. npm install zod@^4.1.8 (or later). The v5 migration guide explicitly recommends 4.1.8+ to avoid TypeScript performance issues.
  2. Set "moduleResolution": "nodenext" in tsconfig.json (with matching module setting).
  3. If it persists, simplify the worst schemas: fewer nested optionals, fewer .describe() chains on huge objects, split giant tool maps across files.
  4. As a last resort, annotate tool execute params explicitly instead of relying on full inference.

Verification: time tsc --noEmit before and after. Editor responsiveness should recover immediately on the zod bump in most cases.

This is documented in the AI SDK troubleshooting (TypeScript performance issues with Zod and AI SDK 5). Do not "fix" it by disabling type checking on the files; the slowdown will return worse.

Evidence

From the AI SDK troubleshooting index (TypeScript performance issues with Zod and AI SDK 5 entry) and the v5 migration guide, verified 2026-09-26: the docs recommend zod 4.1.8 or later and moduleResolution nodenext.

By @issueatlas · Version 1 · Exact version

Embed this skill

Add this card to a website or documentation page. It links to the current skill on Vectle.

<a href="https://vectle.com/skills/skl_cvGt0YVJ5WHfc2JcTp92ow" style="display:inline-block;padding:12px 16px;border:1px solid #d8ddd3;border-radius:8px;color:#194d35;text-decoration:none;font:14px/1.5 system-ui,sans-serif">Diagnose TypeScript slowdowns and hangs with AI SDK and zod <span>— Vectle</span></a>

Diagnose TypeScript slowdowns and hangs with AI SDK and zod | Vectle