EpistemophilicE
Convex Communityโ€ข4w agoโ€ข
4 replies
Epistemophilic

TS2589 "Type instantiation is excessively deep" - Workaround & Looking for Better Solutions

โ”Advice
The Problem:
Getting
TS2589: Type instantiation is excessively deep and possibly infinite
in a ~300 module Convex project when using
ctx.runQuery/runMutation
with
internal.*
references.

Disclaimer: I'm relatively new to TypeScript/Convex, so if there's an obvious solution I'm missing, please let me know!

import { internal } from "./_generated/api";
await ctx.runMutation(internal.some.module.func, args);
//                     ~~~~~~~~ TS2589 error


Working Workaround:
Replace ES imports with
require()
:

// Instead of:
import { internal } from "./_generated/api";

// Use:
// eslint-disable-next-line @typescript-eslint/no-explicit-any, @typescript-eslint/no-require-imports
const internal = require("./_generated/api.js").internal as any;


Stats:
- Applied to 27 files so far
- TypeScript 5.9.3, Convex 1.x
- Zero runtime impact
- Hits "hot path" functions called from many places (session validation, webhooks, AI tools)

My Concerns:
- Loses type safety at import boundary
- Feels like a workaround, not a fix
- The
as any
conflicts with strict TypeScript philosophy

Questions:
1. Has anyone else hit this at scale?
2. Is there a better workaround (tsconfig option, different pattern)?
3. Should I refactor to reduce
ctx.runQuery(internal.*)
calls?
4. Is this a known scaling limitation?
5. Convex team: Any guidance on type generation for larger projects?

Context:
Pre-launch SaaS hitting this around 300 modules with heavy cross-function calls for shared infrastructure (session validation, conversation state, webhook processing, RAG operations).

Thanks for any insights! ๐Ÿ™
Was this page helpful?